I am try to make a class containing another class as member variable. And I encounter the follow problem:
class SubClass{
....
};
class MainClass{
public:
MainClass(SubClass const & subClass_);
private:
SubClass subClass
};
and in the .cpp files for the constructor
MainClass::MainClass(SubClass const & subClass_){
subClass = subClass_;
}
This gives out compiler errors. But the following works:
MainClass::MainClass(SubClass const & subClass_):
subClass(subClass_) {}
Could anyone tell me what is the difference of these two?