I'm looking for an easy way to build an array of strings at compile time. For a test, I put together a class named Strings
that has the following members:
Strings();
Strings(const Strings& that);
Strings(const char* s1);
Strings& operator=(const char* s1);
Strings& operator,(const char* s2);
Using this, I can successfully compile code like this:
Strings s;
s="Hello","World!";
The s="Hello"
part invokes the operator=
which returns a Strings&
and then the operator,
get called for "World!"
.
What I can't get to work (in MSVC, haven't tried any other compilers yet) is
Strings s="Hello","World!";
I'd assume here that Strings s="Hello"
would call the copy constructor and then everything would behave the same as the first example. But I get the error: error C2059: syntax error : 'string'
However, this works fine:
Strings s="Hello";
so I know that the copy constructor does at least work for one string. Any ideas? I'd really like to have the second method work just to make the code a little cleaner.