The following code compiles using GCC 4.4.6 and Comeau 4.3.10.
#include <iostream>
struct A { int name; };
template<typename T> struct C : T { using T::name; };
struct B : private A { friend struct C<B>; };
int main()
{
C<B> o;
o.name = 0;
}
It gives the following error in VC++10:
main.cpp(4): error C2877: 'A::name' is not accessible from 'A' main.cpp(10): error C2247: 'A::name' not accessible because 'B' uses 'private' to inherit from 'A'
What's a good cross-compiler workaround that allows o.name = 0;
?
Note: Adding using A::name
to B
takes care of the problem, but publishes the A::name
member to everyone, whereas it should only be visible to a particular template instantiation, namely C<B>
.
using T::name;
? How is this language feature called ? – Kelulausing
keyword, this should kill the red herring. – Quelpartusing A::name;
intoB
? – Outragetemplate <typename T> friend struct C<T>;
. It's a bit different, but maybe it works? – Outrageusing A::name
w/inB
. – Quelpartusing A::name
does not have any downsides. It shouldn't be necessary according to the standard, but it definitely has no ill effects. Name lookup comes way before access control. But it also doesn't hurt and doesn't get in the way, so feel free to leave it in. – Outragefriend struct C<B>
actually do anything in your example? C inherits from B anyway, and B doesn't have any members of its own. Might be it's just me missing some part of C++ knowledge, though ;). – MucoproteinB
does has a member, namely the privately inheritedA
instance. – Quelpart