vector

STL: how to overload operator= for <vector> ?

There's simple example: #include <vector> int main() { vector<int> veci; vector<double> vecd; for(int i = 0;i<10;++i){ veci.push_back(i); vecd.push_back(i); } vecd = veci; // <- THE PROBLEM } The thing I need to know is how to overload operator = so that I could make assignment like this: vector<double> = vector<int>; I'...

Reference to element in 2d vector (c++)

Hi, I have a class named Spring in a particle system. The constructor looks like: Spring(Particle& _a, Particle& _b); And I have a vector of Particles and I use Spring mySpring = Spring(myParticles.at(j),myParticles.at(j+1)); inside a loop to add a spring force between two particles. Everything works fine so far. However, I want t...

What is the most efficient way to append one std::vector to the end of another?

Let v1 be the target vector, v2 needs to be appended to the back of it. I'm now doing: v1.reserve(v1.size() + v2.size()); copy(v2.begin(), v2.end(), back_inserter(v1)); Is this the most efficient way? Or can it maybe be done just via copying a chunk of memory? Thanks! ...

How do I pass a static method to comp in clojure?

It seems as though I'm having problems accessing Integer.parseInt in comp. I can access it normally like this: user=> (Integer/parseInt "123") 123 But if I put it in comp, I get an error: user=> (def vect-to-int (comp Integer/parseInt (partial apply str))) java.lang.Exception: Unable to find static field: parseInt in class java.lang...

XNA Collision Detection - Vector2.Reflect - Help Calculating the Normal of a Circle Sprite - C#

I'm having trouble wrapping my mind around how to calculate the normal for a moving circle in a 2d space. I've gotten as far as that I'm suppose to calculate the Normal of the Velocity(Directional Speed) of the object, but that's where my college algebra mind over-heats, any I'm working with to 2d Circles that I have the centerpoint, ra...

dynamical two dimension array according to input

Hi, I need to get an input N from the user and generate a N*N matrix. How can I declare the matrix? Generally, the size of the array and matrix should be fixed at the declaration, right? What about vector<vector<int>> ? I never use this before so I need suggestion from veteran. ...

XNA - Why does it use Vector2 and not Point?

I'm used to WinForms graphics, but I've been dabbling in XNA, and one thing I've noticed is that the Point object isn't very useful, and doesn't seem to be used very much. For positioning, the various SpriteBatch Draw methods use either a Rectangle or a Vector2. And Vector2 has a lot of useful static and instance methods, whereas Point...

Need help with understanding STL vector (simple code in body of message)

Here is the code: #include <vector> #include <iostream> class A { public: A() { std::cout << __FUNCTION__ << "\n"; } ~A() { std::cout << __FUNCTION__ << "\n"; } A& operator=(const A&) { std::cout << __FUNCTION__ << "\n"; return *this;} }; int main(int argc, char* argv[]) { std::vector<A> as; A a; as.push_back(...

How do I replace colours in a movieclip?

I am trying to take a movieclip of a character and change the colour of their clothes. The character is comprised of vectors. So far I have semi-sucessfully used this method: stop the movieclip take the bitmap data from the current frame use threshold to replace the colour store the resulting bitmap data in an array add an onenterfram...

Converting EPS to Xaml

I have bunch of EPS vector files that I want to convert to Xaml (WPF version, not Silverlight). What's the best tool for the job (Preferably a free one)? ...

How to get the object type from a collection (vector) of parent objects using RTTI

Hello, I have a base class which has two child classes derived from it. class A {}; class B : public A {}; class C : public A {}; I have another class that has a pointer to collection of class A members using a vector, something like this: vector<A*> *m_collection; And what I do is to create objects of class B or C and add them to...

What's the fastest vector/matrix math library in C for iPhone game?

As the title, I'm finding vector/matrix library in C optimized for iPhone/iPod processors. Or just generally fast. ---(edit)--- I'm sorry for unclear question. I'm looking for fast lib for commercial games for iPhone/iPod. So GPL lib cannot be used. However, I'll stop finding fastest lib, it maybe meaningless. ...

C++: Easiest way to initialize an STL vector with hardcoded elements

I can create an array initialized with elements like this: int a[] = {10, 20, 30}; How do I create an STL vector and initialize it like the above? What is the best way to do so with the minimum typing effort? The best I can do is: std::vector<int> ints; ints.push_back(10); ints.push_back(20); ints.push_back(30); Though I could sh...

Is there any way to specify a generic argument to a function with the restriction that it should implement a given interface

Example: I have a function that works with vectors: double interpolate2d(const vector<double> & xvals, const vector<double> & yvals, double xv, double yv, const vector<vector<double> > &fvals) { int xhi, xlo, yhi, ylo; double xphi, yphi; bracketval(xvals,xv,xhi,xlo,xphi); bracketval(yvals,yv,yhi,ylo,yphi); return (f...

C++ Template class using STL container and a typedef

Hi, I have a class looking like this: #include <vector> #include "record.h" #include "sortcalls.h" template< typename T, template<typename , typename Allocator = std::allocator<T> > class Cont = std::vector> class Sort: public SortCall { This code is working and I'm calling it like this from other classes: Comparator c; // c...

Memory allocation for _M_start and _M_finish in a vector

I'm defining a vector as: vector< int, MyAlloc< int> > *v = new vector< int, MyAllooc< int> > (4); MyAlloc is allocating space for only 4 ints. Memory for _M_start, _M_finish, and _M_end_of_storage is being allocated on the heap before the memory for the 4 ints. But who is allocating this memory for _M_start, _M_finish, and _M_end_of_...

Constant correctness

In the printMessage if you access the vector of a constant class using the index it works fine, but not with the the iterator (*itr). If the iterator is declared as constant_iterator then it works fine. Why? In both cases I am reading the data and not modifying the vector. Can someone shed some light? #include <iostream> #inclu...

Proper vector memory managment

I'm making a game and I have a vector of bullets flying around. When the bullet is finished, I do bullets.erase(bullets.begin() + i); Then the bullet disappears. However it does notseem to get rod of the memory. If I create 5000 bullets then create 5,000 more after those die off, memory stays the same, but if I create 5,000 more while th...

Iterating & containers of smart pointers

I have a container of smart pointers to mutable objects. I have to write two *for_each* loops, one for accessing the objects as read-only data and another for mutable data. The compiler is telling me that std::vector< boost::shared_ptr<Object> > is not the same as std::vector< boost::shared_ptr<const Object> >, note the const. Here ...

[C++] Vector (push_back); g++ -O2; Segmentation fault

I'm having problem with vector, (in the usage of push_back) but it only appears when using additional g++ flag -O2 (I need it). #include <cstdio> #include <vector> typedef std::vector<int> node; typedef std::vector<node> graph; int main() { int n, k, a, b, sum; bool c; graph g(n, node()); c = scanf("%i%i", &n, &k); ...