D
dl
I have two classes, say A and B, both having a data member 'int n';
private in A, public in B.
When I derive class C from both public A and public B, B::n should be
visible to C while A::n should not be.
But if I compile with g++-4.0.3 the following snippet:
class A {
int i;
public:
A () {}
};
class B {
public:
int i;
B () {}
};
class C : public A, public B {
public:
C () { i = 3; }
};
int main () {
C c;
return 0;
}
I get the following error:
test.cpp: In constructor 'C::C()':
test:15: error: reference to 'i' is ambiguous
test:9: error: candidates are: int B::i
test:2: error: int A::i
Nothing dramatic, of course I can change the names or use access
specifiers. I just would like to know if I am misinterpreting chapter 6
of Stroustrup 2nd edition or if this is a compiler problem.
Thanks for the attention,
Daniele
private in A, public in B.
When I derive class C from both public A and public B, B::n should be
visible to C while A::n should not be.
But if I compile with g++-4.0.3 the following snippet:
class A {
int i;
public:
A () {}
};
class B {
public:
int i;
B () {}
};
class C : public A, public B {
public:
C () { i = 3; }
};
int main () {
C c;
return 0;
}
I get the following error:
test.cpp: In constructor 'C::C()':
test:15: error: reference to 'i' is ambiguous
test:9: error: candidates are: int B::i
test:2: error: int A::i
Nothing dramatic, of course I can change the names or use access
specifiers. I just would like to know if I am misinterpreting chapter 6
of Stroustrup 2nd edition or if this is a compiler problem.
Thanks for the attention,
Daniele