Reputation: 3611
If I have two files myclass.h and myclass.cpp how to separate this code to declaration of class member and implementation of constructor where I need to set the values in brackets {}?
std::string predefinedArgs[] = { "Some", "Other", "Strings" };
I tried header:
class Wrapper {
public:
std::map<std::string,std::string> arguments;
Wrapper(int argc, char ** argv);
private:
int argc; char ** argv;
std::vector<std::string> args;
std::string predefinedArgs[12];
void parseArguments();
};
And .cpp:
Wrapper::Wrapper(int argc, char ** argv):
argc(argc),
argv(argv),
args(argv, argv+argc)
{
this->predefinedArgs[] = { "Jan", "Feb", "Mar", "April", "May", "June", "July",
"Aug", "Sep", "Oct", "Nov", "Dec" };*/
// this->parseArguments();
};
which is wrapper.cpp(8): error C2059: syntax error : ']'
I searched net but I cannot find one serious example showing this. Don't you use classes? (just a rhetorical question)
Edit: Init. list also failed:
#include "wrapper.h"
Wrapper::Wrapper(int argc, char ** argv):
argc(argc),
argv(argv),
args(argv, argv+argc),
predefinedArgs({ "Jan", "Feb", "Mar", "April", "May", "June", "July",
"Aug", "Sep", "Oct", "Nov", "Dec" })
{
// this->parseArguments();
};
wrapper.cpp(7): error C2143: syntax error : missing ')' before '{'
Upvotes: 0
Views: 64
Reputation: 666
From the name of predefinedArgs
I guess you might consider using static const member (or other solutions) and put it outside of the constructor completely.
E. g. like this:
.hpp
class Wrapper {
// ...
private:
static const std::string predefinedArgs[12];
};
.cpp
const std::string Wrapper::predefinedArgs[12] = { "Jan", "Feb", "Mar", "April", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec" };
Upvotes: 2