Can someone explain why I cannot initialise a variable in the body of the constructor in the same way as I can do it in the member initialisation list.
class MyClass
{
public:
MyClass();
virtual ~MyClass(void);
private:
std::string test;
};
MyClass::MyClass()
: test("asdf") <-- Case 1: This is OK
{
test("asdf"); <-- Case 2: This is not
}
I'm asking as I have a 3rd party class that I need to use and initialize by passing certain variables into its constructor. It is fine if I use it as in Case 1 above but not as in Case 2.
testas a function.