L
linq936
Hi,
I am confused at static variable in declaring and defining.
I have the following code in header file,
class c0;
class c1 {
static std::vector<c0> cs;
};
And in C file, I operate on c1::cs in some function. But VC7 compiler
complains that c1::cs is not initialized.
I have to add the following line to the top of the C code,
std::vector<c0> c1::cs;
Then it works.
This makes half sense to me. Static variable must be defined in
addition to declaring. But how come the above newly statement does the
definition? Is that because std::vector does some dummy initialization?
Then I have another header file,
class MyString {...};
static MyString myStr; // This variable does not belong to any
class
Then in the C file when I have
myStr = "";
The compiler complains that I am re-defining myStr.
I wonder what is going on? Because myStr is a standalone variable, so
its definition is defferent from class member?
I am confused at static variable in declaring and defining.
I have the following code in header file,
class c0;
class c1 {
static std::vector<c0> cs;
};
And in C file, I operate on c1::cs in some function. But VC7 compiler
complains that c1::cs is not initialized.
I have to add the following line to the top of the C code,
std::vector<c0> c1::cs;
Then it works.
This makes half sense to me. Static variable must be defined in
addition to declaring. But how come the above newly statement does the
definition? Is that because std::vector does some dummy initialization?
Then I have another header file,
class MyString {...};
static MyString myStr; // This variable does not belong to any
class
Then in the C file when I have
myStr = "";
The compiler complains that I am re-defining myStr.
I wonder what is going on? Because myStr is a standalone variable, so
its definition is defferent from class member?