How do you declare an array of classes?

Started by
10 comments, last by chadsxe 16 years, 11 months ago
Quote:Original post by Palidine
or you could use an STL container:
*** Source Snippet Removed ***


std::vector has a constructor for the case where each initial element is the same; there's no need to invoke the subtler stuff from <algorithm>. We don't even need to store things by pointer:

std::vector<Character> Heroes(10, Character(graphics, collision, 100, 100));


In general, adding pointers to your design because "it's hard to do it without pointers" is the wrong design decision: it will make lots of other things harder (at least if you care about doing them properly), and you'll be worse off.


Advertisement
I am having no problems declaring the vector like stated above. When I go to use it though I am getting errors. For example something like...

Heros[2].MoveRight();

is giving me

game.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: class Character & __thiscall std::vector<class Character,class std::allocator<class Character> >::operator[](unsigned int)" (??A?$vector@VCharacter@@V?$allocator@VCharacter@@@std@@@std@@QAEAAVCharacter@@I@Z)
: fatal error LNK1120: 1 unresolved externals

This topic is closed to new replies.

Advertisement