robbio
2010-10-21 18:39:47 UTC
Hi All,
this is the scenario: I have two classes, a base one and a derived one:
class A
{
public:
A(...)
...
protected:
int m_nVariable;
};
class B : public A
{
public:
B(...)
: A()
, m_nVariable( 0 ) <<<< here is the problem
{
....
}
}
*At compile time*, the compiler says me that there is an "ilegal member
initialization: m_nVariable is not a base or a member".
But from the theory I know that m_nVariable visibility is public from B
so m_nVariable is a B's member too and I call it after the
initializzation of A().
If I put "m_nVariable = 0" inside the constructor of B (between { and })
all is fine.
So I don't understand why the compiler doesn't see, at compile time,
m_nVariable as member of B too, in the intialization list of B of course.
Is there a conceptual explanation for this?
I'm using VS2008 but I dont' think it's important.
Thank you,
Roberto
this is the scenario: I have two classes, a base one and a derived one:
class A
{
public:
A(...)
...
protected:
int m_nVariable;
};
class B : public A
{
public:
B(...)
: A()
, m_nVariable( 0 ) <<<< here is the problem
{
....
}
}
*At compile time*, the compiler says me that there is an "ilegal member
initialization: m_nVariable is not a base or a member".
But from the theory I know that m_nVariable visibility is public from B
so m_nVariable is a B's member too and I call it after the
initializzation of A().
If I put "m_nVariable = 0" inside the constructor of B (between { and })
all is fine.
So I don't understand why the compiler doesn't see, at compile time,
m_nVariable as member of B too, in the intialization list of B of course.
Is there a conceptual explanation for this?
I'm using VS2008 but I dont' think it's important.
Thank you,
Roberto