Skip to main content
gamedev.net
🔒 Locked

C++ vector

Started by unknownProdigy Jan 23, 2005 at 10:48 AM 0 replies 450+ views
Original Post
unknownProdigy
unknownProdigy
How do I create a vector pointer and how do I initialize it using the new operator? I tried to do it by doing this: vector * v; v = new vector; Or vector *vectorPtr; vector v; vectorPtr = &v Anyway, my program crashes whenever I call the push_back() function. I tried searching but I couldn't find examples of it.
twanvl
twanvl
Your code should work. In the second case you have to be carefull not to use vectorPtr outside the scope in which v is declared. I tried the following, it gave no errors:
#include <vector>class Object{};int main() {    std::vector<Object>* v = new std::vector<Object>;    v->push_back(Object());    delete v;    return 0;}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.