473,230 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

static vector<string> member;

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
2 5558
weaknessforcats
9,208 Expert Mod 8TB
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
9,208 Expert Mod 8TB
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

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

Similar topics

1
by: Matt Garman | last post by:
What is the "best" way to copy a vector of strings to an array of character strings? By "best", I mean most elegantly/tersely written, but without any sacrifice in performance. I'm writing an...
2
by: ehui928 | last post by:
hi, everybody I am a newbie in STL. When I compile the following program under gcc4.0, I got a the following errors. I wonder whether the form of list< vector<string> > is correct in STL ? //...
5
by: Gary Wessle | last post by:
whats an efficient way to copy a string to a vector<string>? how about this? #include <iostream> #include <string> #include <vector> Using namespace std;
5
by: Martin Jørgensen | last post by:
Hi, The piece of code I'm struggling with is so simple, that I hope nobody wants a complete example for answering the question: -------- string color_line; int data_type = 0; for(...
10
by: Shafik | last post by:
Hello, I am new to C++. I know the reason is probably template instantiation problems ... but what's the *real* reason I cannot declare a: vector<stringv = vector<string>(4); Thanks!...
5
by: Etrex | last post by:
Hello, This is my first attempt at a c++ program, and it is a long post, please bear with me. I'm trying to read in a text file containing a firewall log, make the information...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
6
by: Mr. K.V.B.L. | last post by:
I want to start a map with keys but an empty vector<string>. Not sure what the syntax is here. Something like: map<string, vector<string MapVector; MapVector.insert(make_pair("string1",...
42
by: barcaroller | last post by:
In the boost::program_options tutorial, the author included the following code: cout << "Input files are: " << vm.as< vector<string() << "\n"; Basically, he is trying to print a vector...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.