Hey there,
So far I've found out that one can't initialize a non-static data member on declaration in a class but i need to do that because i should use that data member as the default argument of one of the function members and change it later on execution ( replace it with user input) . do u know anyway around that error ?
Here's the code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class Permute {
std::vector<std::string> permutations;
std::string theString = ""; // Here : error: invalid use of non-static data member
public:
Permute(){}
Permute(std::string str){}
void setString(void); // sets theString with user input
std::string getString(); // returns the theString
bool validString(std::string str); // validates user input
// I need to use it here as the default argument for str
void permute(std::string const_str = "",std::string str = theString );
void printPermutations();
};
I tried not initializing it but i got the same error : invalid use of non-static data member
that's because the default argument should be a known value at compile time, and since my string variable is not initialized, i keep getting that error; this is way I'm trying to initialize it.
Oh, I did not noticed how you use it. It has nothing to do with its value known at compile time or something. You just cannot do that. It is not allowed. Make second overload of your permute function: