Re: // how can I access A::a?
On 13/04/2011 09:01, dick wrote:
/* multi_level_inheritance.cpp */
struct A
{
int a;
};
struct B1 : public A
{
int a;
};
struct B2 : public A
{
int a;
};
struct C : public B1, public B2
{
int a;
};
int main()
{
C ccc;
ccc.a=123;
ccc.B1::a=456;
/* 0030 */ ccc.B1::A::a=789;
}
// c++ multi_level_inheritance.cpp
// multi_level_inheritance.cpp: In function int main():
// multi_level_inheritance.cpp:30: error: A is an ambiguous base of C
// how can I access A::a?
Leaving aside the horrible nature of such code, you can do it via an
intermediate reference:
replace the critical line with:
/* 0030 */ B1 & bbb(ccc);
bbb.A::a = 789;
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]