static STL ?

B

bigc

How can I make a static STL vector like this?

#include <vector>
using namespace std;

class CClass
{
public:
static vector<int> v;
CClass();
};



CClass::CClass()
{
v.push_back (2);
}


main()
{
}



Thanks.
 
A

Attila Feher

bigc said:
How can I make a static STL vector like this?

#include <vector>
using namespace std;

class CClass
{
public:
static vector<int> v;
CClass();
};

vector<int> CClass::v;

You need to define it, int the implementation file of CClass.
 
T

Thomas Matthews

bigc said:
How can I make a static STL vector like this?
You have. Except for you need to define the variable somewhere.
#include <vector>
using namespace std;

class CClass
{
public:
static vector<int> v;
CClass();
};
Add here:
vector said:
CClass::CClass()
{
v.push_back (2);
}


main()
int main(void)
{
}



Thanks.

Please read this website:
http://www.jelovic.com/articles/stupid_naming.htm

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
B

bigc

Thanks. It works.
I'm reading the code about class naming.
It is interesting. Is there any other good forum
where people discuss stuff like this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top