vector

how can to allocate a matrix using vector on the heap

hey, i am trying to allocate a dynamic matrix on the heap and seems like i am doing something wrong. i try to do the following thing : vector< vector<int*> >* distancesMatrix=new vector< vector<int*> >; it does allocate a matrix on the heap but the matrix itself is empty, i want the matrix to be sizeXsize but cant sort it alone when ...

What's wrong with this XNA RotateVector2 function?

Hi, I know this is probably a very simple question, but I can't seem to figure it out. First of all, I want to specify that I did look over Google and SO for half an hour or so without finding the answer to my question(yes, I am serious). Basically, I want to rotate a Vector2 around a point(which, in my case, is always the (0, 0) vecto...

How can I store function pointer in vector?

like: vector<void *(*func)(void *)>... ...

Angle of a vector pointing from A to B

I'm not the best in Maths, but for what I am doing now I need to calculate the angle of the vector which is shown as arrow in the picture below: I have a point A and a point B in a 2D plane. I need to calculate the following: The angle in which the arrow must be rotated in order to point to B ...

Wrap std::vector of std::vectors, C++ SWIG Python

I want to wrap a C++ vector of vectors to Python code by using SWIG. Is it possible to wrap this type of vector of vectors? std::vector<std::vector<MyClass*>>; In the interface file MyApplication.i I added these lines: %include "std_vector.i" %{ #include <vector> %} namespace std { %template(VectorOfStructVector) vector<vecto...

How to use an unknown (int-like) type as index into std::vector?

I'm using a type Id which is defined in another part of the code I'm using: typedef int Id; Now I am provided many objects, each of which comes with such an Id, and I would like to use the Id as index into a std::vector that stores these objects. It may look something like this: std::vector<SomeObj*> vec(size); std::pair<Id, SomeObj*...

Is this use of nested vector/multimap/map okay?

I am looking for the perfect data structure for the following scenario: I have an index i, and for each one I need to support the following operation 1: Quickly look up its Foo objects (see below), each of which is associated with a double value. So I did this: struct Foo { int a, b, c; }; typedef std::map<Foo, double> VecElem; std...

C++: mixture between vector and list: something like std::rope?

Hi, When storing a bunch of items and I don't need random access to the container, I am using an std::list which is mostly fine. However, sometimes (esp. when I just push back entries to the back and never delete somewhere in the middle), I wish I had some structure with better performance for adding entries. std::vector is bad because...

Using "unique()" on a vector of vectors in C++

I hope this is not a duplicate question, but if it is, feel free to point me in the right direction. I have a vector<vector<int> >. Is it possible to use unique() on this? Something like: vector<vector<int> > myvec; //blah blah do something to myvec vector<vector<int> >::interator it = unique(myvec.begin(), myvec.end()); Would the r...

Need help with Direct 3D's LookAt function ..

I need some conceptual help with Direct3D's .... function. In their official documentation, they say that the computation that takes place can be summarized with this: zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)) yaxis = cross(zaxis, xaxis) xaxis.x yaxis.x zaxis.x 0 xaxis.y yaxis.y ...

Questions regarding Vector Array of Structs

I made a post about this yesterday, but it is a fairly different question. Not sure if I should make a new question or just reply to the old one but here goes. Basically I am setting up my vector array of structs as follows.. class Debugger : public Ogre::SimpleRenderable { struct DebugVertex { Ogre::Vector3 v; ...

Why is this vector iterator not incrementable?

i'm trying to delete the vector's content and i'm getting an error - vector iterator is not incrementable, why is that? this is my destructor City::~City() { vector <Base*>::iterator deleteIterator; for (deleteIterator = m_basesVector.begin() ; deleteIterator != m_basesVector.end() ; deleteIterator++) m_basesVector....

(Relatively) Size-Safe Wrapped STL Container in C++

Bear with me because I'm self taught in C++ and am spending my limited extra time on the job to try to learn more about it (I'm a chemical engineering researcher by day). I have a pretty simple objective: 1. Make a size-safe container to store a long list of floats. 2. Make a specialized version of that container that acts as a matri...

Convert std::vector to array

I have a library which expects a array and fills it. I would like to use a std::vector instead of using an array. So instead of int array[256]; object->getArray(array); I would like to do: std::vector<int> array; object->getArray(array); But I can't find a way to do it. Is there any chance to use std::vector for this? Thanks for r...

C vector as char *** vector

A function I need to use requires a vector argument for return storage with the following signature: char ***vvar What am I supposed to pass in there? How do I access elements afterward? ...

C++ std::vector erasing element 0 throws exceptions

Sorry I can't provide code bc I don't have it. My coworker (who has been with the company for a long time but doesn't appear to know what he's doing) claims that he has to do some weird stuff to remove elements from a vector. He moves all the elements down a position (starting at the element that he wants to remove) then he'll remove t...

is it possible for set to have std::vector as underlying storage for storage of its elements?

For small collections std::vector is almost certainly the best container whatever the operations applied to it are. Is it possible to have std::vector as underlying storage for the elements set container instead red-black tree involving a lot of heap allocations (maybe boost has something?) or do I have to invent it myself? Plain std::v...

C++ Constructor error - Expected ')' before token '<'

What is wrong wit the following constructor declaration? I keep getting this error: Expected ')' before token '<' class Environment{ public: Environment(vector<vector<char> > roomData); private: //.... }; Note: ok I see what's wrong. I did not add: using namespace std; ...

std::vector resize() works only after clear().

I have a vector object: std::vector<std::vector<MyClass>> _matrix; It is 2d array with some data. When i trying to resize the dimensions with: _matrix.resize(_rows, std::vector<MyReal>(_colms)); //_rows and _colms are ints this command simply does nothing to the object. So to resize it i have to call first to: _matrix.clear(); a...

C++: Loop over two vectors, remove elements of 1

Hi there, I have the following toy code, intended to remove duplicates from a vector: void overlap_removal(vector<int> &vec1, vector<int> &vec2) { for (vector<int>::iterator it1 = vec1.begin(); it1 != vec1.end(); ++it1) { for (vector<int>::iterator it2 = vec2.begin(); it2 != vec2.end(); ++it2) { if ((*it1)*(*it2) < 10) { ...