vector

C++ vector, return vs. parameter

Possible Duplicate: how to return an object in C++ I am wondering if there is a difference between the three following approaches: void FillVector_1(vector<int>& v) { v.push_back(1); // lots of push_backs! } vector<int> FillVector_2() { vector<int> v; v.push_back(1); // lots of push_backs! return v; } vector...

How can i free a pointer vector?

Hello, how can i free up memory in a pointer vector? Here's the code: class A { private: int x,y,z; public: A(param1, param2, param3) { x=param1; y=param2; z=param3; } ~A() { //prompts an alertbox, warning me about the successful call...

Ruby core Matrix vs NArray's NMatrix

There seems to be two matrix modules in Ruby that I've found Matrix: Part of core Ruby it seems NMatrix: Part of the NArray library At the moment it seems NMatrix is faster, has some more helpful methods, but require a bit more setup. Is there anyone with experience of both who can give a rough overview of why I should use one over ...

Can't shed Java warnings when cloning vector

I have two vectors declared as a private class property: private Vector<Myobject> v1 = new Vector<Myobject>(); private Vector<Myobject> v2 = new Vector<Myobject>(); I fill up v1 with a bunch of Myobjects. I need to do a shallow clone of v1 to v2. I tried: v2 = v1.clone(); I get "unchecked or unsafe operations". I've tried all fo...

get output as a vector in R during a loop

How can I get the output as a vector in R? For example, if I want to have for (i in 1:1000) {if i mod 123345 = 0, a = list(i)} a but I would want to find all i that divide evenly into 123345 (i.e., factors), and not just the largest one. ...

how do i back insert to a vector with a const pointer

hello i have an error with the following code: in my h file i got the following vector: vector<Vehicale*> m_vehicalesVector; and in my cpp file i got the following function: void Adjutancy:: AddVehicale(const Vehicale* vehicaleToAdd) { m_vehicalesVector.push_back(vehicaleToAdd); } seems like the const Vehicale* vehicaleToAdd is...

const and STL containers

The following std::vector code is giving errors int main() { std::vector<const double> VectDouble; VectDouble.push_back(2.34); VectDouble.push_back(2.33); VectDouble.push_back(2.32); for(std::vector<const double> VectDouble::iterator i=VectDouble.begin();i!=VectDouble.end();++i) std::cout<<*i; } ...

Java Vector Question

Is the element in the Vector a clone/copy of the original? SomeType myVar = new SomeType(); myVar.something = "AStringValue"; myVar.i = 123; Vector<SomeType> v1 = new Vector<SomeType>(); v1.add(myVar); Vector<SomeType> v2 = new Vector<SomeType>(); v2.add(myVar); v1.get(0).i = 321; After this code are these statements true v2.get(0)....

Vector class in c++ programing

Can anybody explain me, what is use of vector class? My Professor mentioned about below sentence in the lecture. Template: Each vector has a class parameter that determines which object type will be used by that instance, usually called T. I don't understand what exactly class parameters means? ...

Should we delete before or after erase for an pointer in the vector

Hi , Should we delete before or after erase. My understanding is both are OK. Is it correct? In addition, is there any case we won't want to delete the element while erasing it? I believe there must be , otherwise, the erase will be happy to take the responsibility. std::vector<foo*> bar; ... for (vector<foo*>::iterator itr = bar.be...

What's generally the size limit to switch from a vector to a deque?

I recent wrote this post: http://stackoverflow.com/questions/3737138/how-best-to-store-very-large-2d-list-of-floats-in-c-error-handling Some suggested that I implemented my 2D list-like structure of floats as a vector, others said a deque. From what I gather vector requires continuous memory, but is hence more efficient. Obviously thi...

Runtime error accessing a vector

In my C++ project, I have a class App, and a class Window. Class App has a parameter: vector<Window*>* window;. In App's constructor, it is able to use and push_back a Window* onto this vector fine, but in my onMessage() method, which is called by the WndProc() (I'm using winapi), it gives me an runtime error when I try to use the vecto...

Time and space complexity of vector dot-product computation

Help me! What is the time and space complexity of an algorithm, which calculates the dotproduct between to vectors with the length n. ? ...

std::vector iterator invalidation

There have been a few questions regarding this issue before; my understanding is that calling std::vector::erase will only invalidate iterators which are at a position after the erased element. However, after erasing an element, is the iterator at that position still valid (provided, of course, that it doesn't point to end() after the e...

How to control a kiwi drive robot?

I'm on the FIRST robotics team at my high school, and we are working on developing a kiwi drive robot, where there are three omni wheels mounted in a equilateral triangle configuration, like this: The problem is programming the robot to drive the motors such that that the robot moves in the direction of a given joystick input. For exa...

how to define a vector with a functor

hey, i implemented the following functor: struct CompareCatId : public std::binary_function<Vehicle*, Vehicle*, bool> { bool operator()(Vehicle* x, Vehicle* y) const { if(x->GetVehicleType() > y->GetVehicleType()) return true; else if (x->GetVehicleType() == y->GetVehicleType() && x->GetLicenseNumb...

How to put NULL in all cells of a matrix vector?

Hello, i'm trying to initialize all cells of a matrix with NULL values, but something is wrong here. the code : vector<vector<Distance*> > distanceMatrix; for (int i = 0; i < 7 ; i++) for (int j = 0; j < 7 ; j++) distanceMatrix[i][j].push_back(NULL); i bet it's something stupid, thanks for the help. ...

R: removing the last elements of a vector

Hello How can I remove the last 100 elements of a zoo series? I know the name[-element] notation but I can't get it work to substract a full section ...

How to wrap a c++ vector of vector with SWIG.

Hi, I'm using SWIG to wrap C++ code to Python code. I'm trying to wrap a vector of vectors. The method is: std::vector<std::vector<MyClass*>*> GetMyClassVectorOfVectors(); I'm able to wrap the first vector without adding lines to the file "MyAplication.i": The method is std::vector<MyClass*> GetMyClassVector(); And this is working...

How Do I define a Double Brackets/Double Iterator Operator, Similar to Vector of Vectors'?

I'm porting code that uses a very large array of floats, which may trigger malloc failures from c to c++. I asked a question about whether I should use vectors or deques and Niki Yoshiuchi generously offered me this example of a safely wrapped type: template<typename T> class VectorDeque { private: enum TYPE { NONE, DEQUE, VECTOR }; ...