BigBadWolf
BigBadWolf

Reputation: 603

C++: Dereferencing a vector<vector<class_ptr*>>

I'm trying to store classes in a 2d array, but with empty fields, or holes, i.e. fields that simply have no content. Since the class itself is quite big, I decided to fill the vector with pointers to the class, so empty fields could be simply written as NULL. I instantly hit a Wall. If I try to initialize the first value of the vector like this:

myVector[0][0]* = classToBeCopied;

I get the following errors: "Syntax Error" "expected primary-expression before '=' token"

I do have a working copy-constructor and operator= for the class. (I am using Eclipse Luna) Thank you in advance!

Upvotes: 0

Views: 110

Answers (2)

user2023370
user2023370

Reputation: 11037

Try:

*myVector[0][0] = classToBeCopied;

Upvotes: 3

James Adkison
James Adkison

Reputation: 9602

myVector[0][0]* = classToBeCopied;

If the result of myVector[0][0] is a type class_ptr*. Then you could do the following.

class_ptr* p = myVector[0][0];
*p; // Dereference

Therefore the following should be sufficient

*myVector[0][0]

Upvotes: 2

Related Questions