The following code doesn’t build.
struct some_struct {
some_struct() {
... do something here to specify size of v; how ??
}
enum {
ZERO,
ONE,
TWO
};
static std::vector<std::string> v(TWO);
};
Appreciate any ideas.. nothing seems to suggest this is illegal use.
Typo: Fixed the vector syntax and correction: I have only tested on 2005/2008, not 2010. The error message for those who asked:
error C2061: syntax error : identifier 'TWO'
Further edit:
It looks like the compiler thinks v is a function that returns type std::vector<std::string>; all of this is inside a struct (I have now further corrected my post to clarify this some more). Perhaps I need to leave out the size argument which it confuses with a type and declare the size somewhere in the constructor? I meant for this vector to be a static data member of the struct. How do I get the compiler to understand this?
NOTE: On Linux I tested it on a standalone code resembling what I had up originally (without the struct)… so maybe it wouldn’t compile on Linux with this correction. So I removed the comment that it built OK on Linux. Apologies.
You can’t initialize the class member in the class declaration. You need to instantiate it outside: