0
我有一個類,它命名爲A,並且一個類在其私有中另有3個類。初始化其他類構造函數內的類對象
class A{
public:
A();
A(int num);
A(C& mC, P& mP, M& mM, int num);
//there is a getter and setter for all member this only one example(please check are they right?)
M getM()const{return pM;}
void setM(M classM){ pM = classM ;}
private:
C& pC;
P& pP;
M& pM;
int digit= 0;
};
我這樣做,在參數constucture:
A::A(C& mC, P& mP, M& mM, int num):pC(mc),pP(mP),pM(mM)
{
// doing someting here
}
但我不能寫默認和第一個參數建設淺析代碼,當我寫的東西編譯器對我說的是:
error: uninitialized reference member in ‘class A&’ [-fpermissive] A::A(){
和
note: ‘A& A::pP’ should be initialized A& pP;
有些像這樣,幾個錯誤和筆記。
我該怎麼辦?我如何初始化默認和第一個參數結構中的類?
仍然我找不到任何解決方案。 –