範例

class MyClass {
public:
MyClass (char *nameInput, int twoInput, int threeInput);
private:
char *one;
int two, three;
int four;
};

MyClass::MyClass (char *nameInput, int twoInput, int threeInput) : two(twoInput), one(nameInput), three(threeInput), four(twoInput + threeInput)
{
}


解決方案
請依照宣告的相同順序來起始設定類別成員。

class MyClass {
public:
MyClass (char *nameInput, int twoInput, int threeInput);
private:
char *one;
int two, three;
int four;
};

MyClass::MyClass (char *nameInput, int twoInput, int threeInput) : one(nameInput), 
two(twoInput), three(threeInput), four(twoInput + threeInput)
{
}