Here is the code:
class Base
{
public:
Base();
protected:
int m_data1;
private:
int m_data2;
};
Base::Base()
:m_data1(0),
m_data2(0)
{
}
class Derived : public Base
{
public:
struct score{
int courses;
int avg;
};
Derived();
private:
score m_score;
int m_data3;
};
Derived:erived()
:Base(),
m_data3(0)
{
m_data1=10;
m_score.courses=0;
m_score.avg=0;
}
Question:
If in Derived:erived(), initilize the data member as below:
Derived:erived()
:Base(),
m_data1(10),
m_score.courses(0),
m_score.avg(0),
m_data3(0)
{
}
I got compiler errors. Anyone knows the rule here? m_data1, and m_score are derived class data member, why am I not allowed to initilize like this?
Thanks for reply.