The error says, "[Error] expected ')' before string constant".
Why would the same syntax work in main but not in a class?
I've tried getting rid of the private and const keywords, but the error persists. Any suggestions would be greatly appreciated.
It'll work if you set it in the default constructor.
that doesnt make any sense. a default constructor is one the compiler generates if you dont have a constructor, so you can't place code in it. as to op: what you need to do is this:
@naraku&GRex: my bad. i wasnt aware c++ had its own meaning. i thought it was the oop def
@op: yes. it calls the the constructor at declaration. the reason this http://www.cplusplus.com/forum/beginner/113905/#msg622066 doesnt work is because constructors can only be called upon the declaration of the variable, not willy nilly. the reason why http://www.cplusplus.com/forum/beginner/113905/#msg622067 works is because you essentially wrote the same thing i did, except you did it outside of the class, which is useful when you have large methods. there might be other performance issues, but thats the major one imo