Reputation: 176
I have a class, it names A and A class has 3 another class in its private.
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;
};
I'm doing that in parameter constucture:
A::A(C& mC, P& mP, M& mM, int num):pC(mc),pP(mP),pM(mM)
{
// doing someting here
}
But I can't write a code for default and first parameter constructure, when I write something compiler saying to me that :
error: uninitialized reference member in ‘class A&’ [-fpermissive] A::A(){
and
note: ‘A& A::pP’ should be initialized A& pP;
someting like this, several errors and notes.
What should I do? How can I initialize classes in default and first parameter constructure?
Upvotes: 0
Views: 113
Reputation: 19128
Class A
contains references to other object. Unlike pointers, references cannot be null. To make this work, you either need to:
nullptr
is no valid object is provided in the constructorUpvotes: 1