sank
sank

Reputation: 5

how to initialize the vector with class pointer(STL)

just want to know to initialize the vector with class pointe

# include <animation> // a class
std::vector<animation*> animlist;
animlist = new std::vector<animtion*>();

but it shows error "error C2678"

Upvotes: 0

Views: 181

Answers (2)

Yan Jiang
Yan Jiang

Reputation: 1

you don't initialize a vector. vector is a container. it's good to go when you declare it. you initialize an object, and push it to the container.

Upvotes: 0

juanchopanza
juanchopanza

Reputation: 227608

Your vector is not a pointer, and it is already initialized here:

std::vector<animation*> animlist; // size 0 vector of animation pointers

What you do in the next line is to attempt to assign a pointer to an std::vector<animaiton*> to animlist. This doesn't work because a vector does not have an assignment operator that takes a pointer to a vector of the same type.

Upvotes: 3

Related Questions