Search Results

Search found 2562 results on 103 pages for 'vector'.

Page 85/103 | < Previous Page | 81 82 83 84 85 86 87 88 89 90 91 92  | Next Page >

  • C++ virtual + protected?

    - by user346113
    Hi, In C++, I have a base class A, a sub class B. Both have the virtual method Visit. I would like to redefine 'Visit' in B, but B need to access the 'Visit' function of each A (and all subclass to). I have something like that, but it tell me that B cannot access the protected member of A! But B is a A too :-P So, what can I do? class A { protected: virtual Visit(...); } class B : public class A { protected: vector<A*> childs; Visit(...); } B::Visit(...) { foreach(A* a in childs) { a->Visit(...); } } Thx

    Read the article

  • MATLAB pdist function

    - by James
    Hi, I am using the pdist command to find the distance between x and y coordinates stored in a matrix. X = [100 100; 0 100; 100 0; 500 400; 300 600;]; D = pdist(X,'euclidean') Which returns a 15 element vector. : [0.734979755525412 3.40039811339820 2.93175207511321 1.83879677592575 2.40127440268306 2.75251513299386 2.21488402640753 1.10610649500317 1.81674017301699 0.903207751535635 1.99116952754924 1.05069952386082 1.24122819418333 1.08583377275532 1.38729428638035] Is there a way to associate these distances with the coordinates they were derived from, i.e. store them in a matrix with the general row form: [Length xcoordinate1 ycoordinate1 xcoordinate2 ycoordinate2] Where there is a row for each length found? Thanks in advance

    Read the article

  • How would you write this Clojure snippet in Ruby and/or Haskell?

    - by dnolen
    I was working on a Rails template and was trying to write a bit of code that allows me to populate a table or multiple columns of ul tags "top-to-bottom" and "left-to-right" across however many columns I specify. I'm just getting the hang of Ruby so I couldn't figure this out. I'm also curious about an idiomatic Haskell version for this useful snippet. Improvements to Clojure version appreciated: (defn table [xs & {:keys [cols direction] :or {cols 1 direction 'right}}] (into [] (condp = direction 'down (let [c (count xs) q (int (/ c cols)) n (if (> (mod c q) 0) (inc q) q)] (apply map vector (partition n n (repeat nil) xs))) 'right (map vec (partition cols cols (repeat nil) xs))))) With this bit of code I can then do the following: (table (range 10) :cols 3) Printed out this would look like so: 0 1 2 3 4 5 6 7 8 9 And the trickier one: (table (range 10) :cols 3 :direction 'down) Looks like so: 0 4 8 1 5 9 2 6 3 7

    Read the article

  • Need recommendation for object serialization library in c++

    - by michael
    Hi, I am looking for recommendation for object serialization/deserialization library in c++? Which one are the most advanced and open-sourced? Can it handle Any class that users defined? Object hierarchy (parent and child classes)? A Tree of objects? Class A has an attribute of Class B which has an attribute of Class C? STL containers? Class A has a vector of Class B? A cyclic of objects? Class A has a pointer pointing to B which has a pointer to A? I find boost serialization library. I am not sure what is its limitation from http://www.boost.org/doc/libs/1_42_0/libs/serialization/doc/tutorial.html

    Read the article

  • Constructor Definition

    - by mctl87
    Ok so i have a class Vector: #include <cstdlib> class Vec { private: size_t size; int * ptab; public: Vec(size_t n); ~Vec() {delete [] ptab;} size_t size() const {return size;} int & operator[](int n) {return ptab[n];} int operator[](int n) const {return ptab[n];} void operator=(Vec const& v); }; inline Vec::Vec(size_t n) : size(n), ptab(new int[n]) { } and the problem is that in one of my homework exercises i have to extend constructor def, so all elements will be initialized with zeros. I thought i know the basics but cant get through this dynamic array -.- ps. sry for gramma and other mistakes ;)

    Read the article

  • Proper use of use of "cor" function in R

    - by order
    I am interested to know what a proper x (vector matrix or data frame) input looks like. I am currently using the function in two different sorts of matrices. However, I am not sure how R would interpret my data the way I intend. I will explain the types of matrix by example. Type 1 Gene1 Gene2 Gene3 sample1 sample2 Type 2 Sample1 Sample2 Sample3 gene 1 gene 2 gene 3 Are either of these formats valid x parameters? I input both of types of matrices and get some results, but without knowing whether or not this a proper use the function, these are just random numbers. Thank you for your time. I apologize that this isn't more interesting.

    Read the article

  • C++ - How to call a member function for an inherited object.

    - by Francisco P.
    Hello! I have a few classes (heat, gas, contact, pressure) inheriting from a main one (sensor). I have a need to store them in a vector<Sensor *> (part of the specification). At some point in time, I need to call a function that indiscriminately stores those Sensor *. (also part of the specification, not open for discussion) Something like this: for(size_t i = 0; i < Sensors.size(); ++i) Sensors[i]->storeSensor(os) //os is an ofstream kind of object, passed onwards by reference Where and how shall storeSensor be defined? Is there any simple way to do this or will I need to disregard the specification? Mind you, I'm a beginner! Thanks for your time!

    Read the article

  • How to retrieve all keys (or values) from a std::map?

    - by Owen
    This is one of the possible ways I come out: struct RetrieveKey { template <typename T> typename T::first_type operator()(T keyValuePair) const { return keyValuePair.first; } }; map<int, int> m; vector<int> keys; // Retrieve all keys transform(m.begin(), m.end(), back_inserter(keys), RetrieveKey()); // Dump all keys copy(keys.begin(), keys.end(), ostream_iterator<int>(cout, "\n")); Of course, we can also retrieve all values from the map by defining another functor RetrieveValues. Is there any other way to achieve this easily? (I'm always wondering why std::map does not include a member function for us to do so.)

    Read the article

  • How to check whether iterators form a contiguous memory zone?

    - by Vincent
    I currently have the following function to read an array or a vector of raw data (_readStream is a std::ifstream) : template<typename IteratorType> inline bool MyClass::readRawData( const IteratorType& first, const IteratorType& last, typename std::iterator_traits<IteratorType>::iterator_category* = nullptr ) { _readStream.read(reinterpret_cast<char*>(&*first), (last-first)*sizeof(*first)); return _readStream.good(); } First question : does this function seem ok for you ? As we read directly a block of memory, it will only work if the memory block from first to last is contiguous in memory. How to check that ?

    Read the article

  • Intersection of line and rectangle with maximum segment length

    - by Aarkan
    I have a vector represented by the slope m. Then there is rectangle (assume axis aligned), which is represented by top-left and bottom-right corner. Of course, there may be many lines with slope m and intersecting the given rectangle. The problem is to find out the line whose length of line intercept inside the rectangle is maximum among all such lines. i.e., if the line intersects rectangle at P1 and P2, then the problem is to find the equation of line for which length of P1P2 is maximum. I proceeded like this. Let the line is: y = m*x + c. Then find out the intersection with each side of rectangle and finding out the maxima for distance function between each pair of points. But it will only give me the length of line segment and there seem to be many corner cases to handle. Could anyone please suggest a better way to do this. Thanks in advance.

    Read the article

  • lambda+for_each+delete on STL containers

    - by rubenvb
    I'm trying to get a simple delete every pointer in my vector/list/... function written with an ultra cool lambda function. Mind you, I don't know c**p about those things :) template <typename T> void delete_clear(T const& cont) { for_each(T.begin(), T.end(), [](???){ ???->delete() } ); T.clear(); } I have no clue what to fill in for the ???'s. Any help is greatly appreciated!

    Read the article

  • Evaluation of (de)reference operators

    - by Micha
    I have an (uncommented...) source file which I'm trying to understand. static const Map *gCurMap; static std::vector<Map> mapVec; then auto e = mapVec.end(); auto i = mapVec.begin(); while(i!=e) { // ... const Map *map = gCurMap = &(*(i++)); // ... } I don't understand what &(*(i++)) does. It does not compile when just using i++, but to me it looks the same, because I'm "incrementing" i, then I'm requesting the value at the given address and then I'm requesting the address of this value?!

    Read the article

  • specyfic syntax question

    - by bua
    Hi there, Is it possible to create template to the initialization like: template <typename C> typename C::value_type fooFunction(C& c) {...}; std::vector<string> vec_instance; fooFunction(cont<0>(vec_instance)); fooFunction(cont<1>(vec_instance)); In general i'm interested is it possible to specify template using integer (ie. 0) instead of true type name. And how to achieve above?

    Read the article

  • C++ - Efficient container for large amounts of searchable data?

    - by Francisco P.
    Hello, everybody! I am implementing a text-based version of Scrabble for a College project. My dictionary is quite large, weighing in at around 400.000 words (std::string). Searching for a valid word will suck, big time, in terms of efficiency if I go for a vector<string> ( O(n) ). Are there any good alternatives? Keep in mind, I'm enrolled in freshman year. Nothing TOO complex! Thanks for your time! Francisco

    Read the article

  • How to figure out "progress" while sorting?

    - by Mehrdad
    I'm using stable_sort to sort a large vector. The sorting takes on the order of a few seconds (say, 5-10 seconds), and I would like to display a progress bar to the user showing how much of the sorting is done so far. But (even if I was to write my own sorting routine) how can I tell how much progress I have made, and how much more there is left to go? I don't need it to be exact, but I need it to be "reasonable" (i.e. reasonably linear, not faked, and certainly not backtracking).

    Read the article

  • Why is the destructor of the class called twice ?

    - by dicaprio
    Apologies if the question sounds silly, I was following experts in SO and trying some examples myself, and this is one of them. I did try the search option but didn't find an answer for this kind. class A { public: A(){cout<<"A Contruction"<<endl;} ~A(){cout<<"A destruction"<<endl;} }; int main() { vector<A> t; t.push_back(A()); // After this line, when the scope of the object is lost. } Why is the destructor of the class called twice ?

    Read the article

  • C++ Questions about vectors

    - by xbonez
    Hey guys, I have a CS exam tomorrow. Just want to get a few questions cleared up. Thanks a lot, and I really appreciate the help. Que 1. What are parallel vectors? Vectors of the same length that contain data that is meant to be processed together Vectors that are all of the same data type Vectors that are of the same length Any vector of data type parallel Que 2. Arrays are faster and more efficient than vectors. True False Que 3. Arrays can be a return type of a function call. True False Que 4. Vectors can be a return type of a function call. True False

    Read the article

  • Twin edges - Half edge data structure

    - by Pradeep Kumar
    I have implemented a Half-edge data structure for loading 3d objects. I find that the part of assigning twin/pair edges takes the longest computation time (especially for objects which have hundreds of thousands half edges). The reason is that I use nested loops to accomplish this. Is there a simpler and efficient way of doing this? Below is the code which I've written. HE is the half-edge data structure. hearr is a vector containing all the half edges. vert is the starting vertex and end is the ending vertex. Thanks!! HE *e1,*e2; for(size_t i=0;i<hearr.size();i++){ e1=hearr[i]; for(size_t j=1;j<hearr.size();j++){ e2=hearr[j]; if((e1->vert==e2->end)&&(e2->vert==e1->end)){ e1->twin=e2; e2->twin=e1; } } }

    Read the article

  • inputMismatchException Java reading doubles from plain text file

    - by user939287
    Using double variable = inputFile.nextDouble(); Gives the mismatch error and I can't figure out why... Anyone know what's up? The input file is just a bunch of doubles like 5.0... Okay here is the code snippet String fileName; Scanner scanner = new Scanner(System.in); System.out.println("\nEnter file name that contains the matrix and vector: "); fileName = scanner.nextLine(); Scanner inputFile = new Scanner(fileName); double a1 = inputFile.nextDouble(); the input file is a plain text document .txt in this format 5.0 4.0 -3.0 4.0 2.0 5.0 6.0 5.0 -2.0 -13.0 4.0 12.0 I don't understand why it wouldn't take those as doubles... As far as what its expecting the format of the file to be... I suppose binary? isn't that the default? I didn't specify in the code...

    Read the article

  • Create a table of Quantiles in R for multiple Subsets of Data

    - by user1489719
    I'm trying to create append a table of quantiles in R for multiple subsets of data. Right now, I have a vector of ids (p_ids) in table DATA, which are not consecutive. For each value in p_ids, I am looking to list the quantile. So far, I've tried variations of: i <- 1 n <- 1 for (i in p_ids) { while(n <= nrow(data)) { quantiles[n] <- quantile(subset(alldata$variableA, alldata$variableB == i),probs = c(0,1,2,3)/3) n <- n + 1 } } I know my issue lies somewhere in the index, but I can't seem to get where the index should go. Suggestions?

    Read the article

  • Why only random-access-iterator implements operator+ in C++?

    - by xopht
    I'd like get far next value for STL list iterator but it doesn't implement operator+, vector has it though. Why and how can I get the value where I want? I think I can do that if I call operator++ several times, but isn't that a little bit dirty? What I want to do is the following: list<int> l; ...omitted... list<int>::iterator itr = l.begin() + 3; // but, list iterator does not have // operator+ What is the best solution for what I want?

    Read the article

  • C++ setting up "flags"

    - by sub
    Example: enum Flags { A, B, C, D }; class MyClass { std::string data; int foo; // Flags theFlags; (???) } How can I achieve that it is possible to set any number of the "flags" A,B,C and D in the enum above in an instance of MyClass? My goal would be something like this: if ( MyClassInst.IsFlagSet( A ) ) // ... MyClassInst.SetFlag( A ); //... Do I have to use some array or vector? If yes, how? Are enums a good idea in this case?

    Read the article

  • C++: Copying to dereferenced pointer...

    - by bbb
    Hi. I currently have a weird problem with a program segfaulting but im not able to spot the error. I think the problem boils down to this. struct S {int a; vector<sometype> b;} S s1; // fill stuff into a and b S* s2 = new S(); *s2 = s1; Could it be that the final copying is illegal in some way? Im really confused right now... Thanks

    Read the article

  • Error occurs while using SPADE method in R

    - by Yuwon Lee
    I'm currently mining sequence patterns using SPADE algorithm in R. SPADE is included in "arulesSequence" package of R. I'm running R on my CentOS 6.3 64bit. For an exercise, I've tried an example presented in http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Sequence_Mining/SPADE When I tried to do "cspade(x, parameter = list(support = 0.4), control = list(verbose = TRUE))" R says: parameter specification: support : 0.4 maxsize : 10 maxlen : 10 algorithmic control: bfstype : FALSE verbose : TRUE summary : FALSE preprocessing ... 1 partition(s), 0 MB [0.096s] mining transactions ... 0 MB [0.066s] reading sequences ...Error in asMethod(object) : 's' is not an integer vector When I try to run SPADE on my Window 7 32bit, it runs well without any error. Does anybody know why such errors occur?

    Read the article

  • what to use in place of std::map::emplace?

    - by kfmfe04
    For containers such as std::map< std::string, std::unique_ptr< Foo >>, it looks like emplace() has yet to be implemented in stdc++ as of gcc 4.7.2. Unfortunately, I can't store Foo directly by value as it is an abstract super-class. As a simple, but inefficient, place-holder, I've just been using std::map< std::string, Foo* > in conjunction with a std::vector< std::unique_ptr< Foo >> for garbage collection. Do you have a interim solution that is more efficient and more easily replaced once emplace() is available?

    Read the article

< Previous Page | 81 82 83 84 85 86 87 88 89 90 91 92  | Next Page >