G
galathaea
after reviewing some code that was not compiling
i found the following simple program could reproduce the issue
-+-+-+-
class Base
{
private:
int data_;
};
// note the private inheritance
class Derived : Base
{
private:
};
class UltraDerived : public Derived
{
private:
Base aBaseAsMember_;
};
int main()
{
UltraDerived myUDerived;
}
-+-+-+-
gcc of various versions
(4.2.1 for instance)
responds "error: class Base is inaccessible"
msvs 2008 (9.0.30729.1 SP)
responds "error C2247: 'Base' not accessible because 'Derived' uses
'private' to inherit from 'Base'"
apparently the private inheritance hides access to the type name
even for an entirely unrelated attempt at containment
is there a technical reason this is not allowed?
i can't see that this would cause cyclic dependencies
(and cyclic dependencies isn't something the syntax tries to prevent
elsewhere)
or compiler bugs?
(the use of this kind of construct is pretty dubious
but it turned up in usage of a third party library
which had taken the unfortunate decision of the private inheritance
of a utility class that the derived needed another copy of)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
galathaea: prankster, fablist, magician, liar
i found the following simple program could reproduce the issue
-+-+-+-
class Base
{
private:
int data_;
};
// note the private inheritance
class Derived : Base
{
private:
};
class UltraDerived : public Derived
{
private:
Base aBaseAsMember_;
};
int main()
{
UltraDerived myUDerived;
}
-+-+-+-
gcc of various versions
(4.2.1 for instance)
responds "error: class Base is inaccessible"
msvs 2008 (9.0.30729.1 SP)
responds "error C2247: 'Base' not accessible because 'Derived' uses
'private' to inherit from 'Base'"
apparently the private inheritance hides access to the type name
even for an entirely unrelated attempt at containment
is there a technical reason this is not allowed?
i can't see that this would cause cyclic dependencies
(and cyclic dependencies isn't something the syntax tries to prevent
elsewhere)
or compiler bugs?
(the use of this kind of construct is pretty dubious
but it turned up in usage of a third party library
which had taken the unfortunate decision of the private inheritance
of a utility class that the derived needed another copy of)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
galathaea: prankster, fablist, magician, liar