this compiles on my other computer, but not this one.
What is wrong with this data member? Why would it compile on one pc, but not another (both OS's are the same and same version, using roughly the same compiler version )
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <string>
#include <vector>
class Utilities{
public:
std::string s = "";
};
int main(){
Utilities util;
}
1 2 3
test2.cpp:7:19: sorry, unimplemented: non-static data member initializers
test2.cpp:7:19: error: in-class initialization of static data member āsā of non-literal type
Being able to initialize non-static members in the class like that is a C++11 feature that not all compilers support. It's likely that the compiler on your other computer was a later version and supported it, whereas the compiler you're using now is older and does not.
Regardless... it's pointless to construct a string with "" because strings are default constructed to be empty anyway. So you can do this and literally have the exact same result:
oh wow, the 4.8 g++ compiler has a carat indicator
1 2 3
test2.cpp:8:3: error: āsā does not name a type
s = "test";
^
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <string>
#include <vector>
class Utilities{
public:
std::string s;
s = "test";
};
int main(){
Utilities util;
}
i still dont know why i am getting this error though, i upgraded gcc and g++ from 4.6 to 4.7, then from 4.7 to 4.8, and i still get the same error on this computer. the other computer is using 4.7. What else could it be?