By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,333 Members | 678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,333 IT Pros & Developers. It's quick & easy.

static vector<string> member;

P: 1
hi!

there is a class:

Expand|Select|Wrap|Line Numbers
  1. class card
  2. {
  3. static vector<string> names;
  4. //...
  5. };
  6.  
  7. //i tried to initialize this way:
  8.  
  9. vector<string> names.push_back("Two of Diamonds");
//but it gives this error:
//error C2143: syntax error : missing ';' before '.'

//i tried to init in the ctor, but that is gave another error, a link error:


//Error : unresolved external symbol "public: static class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > card::names" (?names@card@@2V?$vector@V?$basic_string@DU?$char_ traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@ V?$basic_string@DU?$char_traits@D@std@@V?$allocato r@D@2@@std@@@2@@std@@A)

i have no idea how could i initialize the names variable with several stings
or... is it impossible?
Jul 21 '07 #1
Share this Question
Share on Google+
2 Replies

weaknessforcats
Expert Mod 5K+
P: 9,197
Declaring a static class member does not create the class member.

If it did, every time you incuded you class definition in your code you would get a new static class member which would name collide with the old one.

You have to define (int the class you obnly declare) your static member. Thsat, you have to create it yourself:


vector<string> card::names;

int main()
{

}
Jul 22 '07 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
Declaring a static class member does not create the class member.

If it did, every time you incuded you class definition in your code you would get a new static class member which would name collide with the old one.

You have to define your static member (in the class you only declare it) . That, you have to create it yourself:

Expand|Select|Wrap|Line Numbers
  1. vector<string> card::names;
  2.  
  3. int main()
  4. {
  5.     card c;
  6. }
  7.  
The larger issue is why is this thing static???
Jul 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.