From this article "Initializing C++ Class Members"
It says: There's simply no other way to pass the argument to m_member
which means we cannot. But I don't understand we cannot write:
class CMyClass {
CMember m_member(2);
public:
CMyClass();
};
In this article: How do C++ class members get initialized if I don't do it explicitly?
It has a constructor that allows you specify its initial value CDynamicString(wchat_t* pstrInitialString).
To 'hard code' the registry key name to which this writes you use braces:
class Registry_Entry{
public:
Registry_Entry();
~Registry_Entry();
Commit();//Writes data to registry.
Retrieve();//Reads data from registry;
private:
CDynamicString m_cKeyName{L"Postal Address"};
CDynamicString m_cAddress;
};
From my own test, we cannot use
CMember m_member(2);
in the header file. But why?
And how come
CDynamicString m_cKeyName{L"Postal Address"};
can work? (BTW, I suspect there was a typo. It should remove "L".