vector

STL Vector Corruption Across VS Projects

I have a Visual Studio 2005 solution with several projects that build independently of each other. The main project statically links the other projects. I'm getting very strange STL vector corruption in one of those statically-linked libraries. For example, I declare a std::vector and then perform a sort( thatVector.begin(), thatVector.e...

Insert doubles in cell array into vector in Matlab

How can I take the first row of a cell array that contains doubles and insert it into a vector, without using a 'for' loop? ...

Why don't std::vector's elements need a default constructor?

And how can I write my own array class to not need a default constructor for its elements? Right now, when I do the new [] to allocate space, I need a default constructor. std::vector does not. How do they do this magic? ...

Creating a shape using series of Vector2 - XNA

In my XNA game, I needed to define an irregular shape based on several Vector2 coordinates in the 2D space. The reason was to do collision check (like Rectangle.Intersects()). For example: Vector2 point1 = new Vector(20,30); Vector2 point2 = new Vector(60,30); Vector2 point3 = new Vector(60,80); Vector2 point4 = new Vector(40,90); Vect...

Does std::vector call the swap function when growing? Always or only for some types?

As far as I know I can use a vector of vectors (std::vector< std::vector >) and this will be quite efficient, because internally the elements will not be copied, but swapped, which is much faster, because does not include coping of the memory buffers. Am I right? When does std::vector exactly make use of the swap function? I can't find ...

sorting vectors based on size()

i have a 2-d vector like vector < vector < coordinates > > v( points); where coordinates class is: class coordinate{ public : int x; int y; coordinate(){ x=0; y=0; } }; and points is 20. how to sort the individual vectors v[i] based on v[i].size() , ie based on number of coordinates objects pushed ...

How to add all items in a String array to a vector in Java ?

My code looks like this : Vector<String> My_Vector=new Vector<String>(); String My_Array[]=new String[100]; for (int i=0;i<100;i++) My_Array[i]="Item_"+i; ...... My_Vector.addAll(My_Array); But I got an error message, what's the right way to do it, without looping to add each item ? Frank ...

Where is the memory for a local C++ vector allocated?

I noticed that the memory for vector is allocated dynamically. So for a local vector, where does the memory is allocated? f(){ vector<int> vi; } ...

What is the MPI code to extract a 2D sub-matrix from a larger 2D matrix?

Hello all. I am looking for the best way of extracting a 2D sub-matrix from a larger 2-D submatrix. That is. If I have a matrix with 1 ghost point on each edge, I want to extract the interior matrix. So if the matrix is defined as matrix[NX+2][NY+2] how do I extract out the submatrix starting at matrix[1][1] going to matrix[NX+1][NY+1] ...

Pure Virtual Class and Collections (vector?)

Hello, I'm working on a graphics application that is using virtual classes fairly extensively. It has: A picture class, which is essentially a collection of shapes. A shapes class, which is purely virtual and has a few classes that inherit from it: Circle Polygon Rectangle A Figure shape, which is any graphical figure (also virtual...

Adding an Object to Vector loses Reference using Java?

I have a Vector that holds a number of objects. My code uses a loop to add objects to the Vector depending on certain conditions. My question is, when I add the object to the Vector, is the original object reference added to the vector or does the Vector make a new instance of the object and adds that? For example, in the following code...

Image Line Trace Math Help Hard To Explain

Hi all, sorry for the confusing title, its really hard for me to explain what i want. So i created this image :) Ok so the two RED dots are points on an image. The distance between them isnt important. What I want to do is, Using the coordinates for the two dots, work out the angle of the space between them (as shown by the black line...

Vector iterator

I have class CBase { ....... }; class CDerived : public CBase { ...... }; vector<CBase*> mpBase; vector<CDerived*>::iterator InfoIt; InfoIt=mpBase.begin(); VC++ 2008 generates error C2679. What's wrong? ...

C++, vector of objects

In c++, is using a vector of objects a good idea? If not, what's wrong with this c++ code? #include <vector> using namespace std; class A {}; int main() { vector<A*> v ( new A); return 0; } from g++: 13: error: invalid conversion from A*' tounsigned int' ...

How should I go about generating every possible map<char, char> combination from map<char, vector<char> > ?

I am looking to take a map<char, vector<char> > and generate each possible map<char, char> from it. I understand this may use a sizeable amount of memory and take a bit of time. Each map<char, char> needs to contain every letter a-z, and be mapped to a unique a-z character. ie. ak bj cp dy ev fh ga hb ir jq kn li mx nc oo pz qs rl sd t...

Java ME ArrayList - Vector - Define object types and access object methods through vector

Hi there, I'm making a shopping list mobile application (Java ME) and i have two classes; item, list. item object allows get/set name and quantity (string itemName, int quantity) Now i need to store an array of items in my list class and be able to access the methods of the object from its list array index as follows; code below is ps...

One question about vector push_back

I just noticed that for vector push_back it is push back a reference to the element. void push_back ( const T& x ); My question is does the memory layout changed after push_back? For example, I have an array first which containing five elements and the layout is like this. | | | | | | ...

How do I return a Vector java

How do I return a vector in a java function. I want to unserialize a vector loaded from a file and return in a function but I get errors. This is what code I currently have. private static Vector<Countries> loadOB(String sFname) throws ClassNotFoundException, IOException { ObjectInputStream oStream = new ObjectInputStream(ne...

How to initialize std::vector from C-style array?

What is the cheapest way to initialize a std::vector from a C-style array? Example: In the following class, I have a vector, but due to outside restrictions, the data will be passed in as C-style array: class Foo { std::vector<double> w_; public: void set_data(double* w, int len){ // how to cheaply initialize the std::vector? } ...

How can I partition a vector?

How can I build a function slice(x, n) which would return a list of vectors where each vector except maybe the last has size n, i.e. slice(letters, 10) would return list(c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), c("k", "l", "m", "n", "o", "p", "q", "r", "s", "t"), c("u", "v", "w", "x", "y", "z")) ? ...