A
Amol Chavan
I was debating with my friend on how to make a class final as in java,
where it can't be further derived but instatiated. So I search the net
and found to do so. Make a base class which has constructor private.
And a Final class inheriting from it privately.
// Code snippet
class FinalBase
{
FinalBase() {}
friend class Final;
};
class Final : virtual private FinalBase
{
public:
};
class DerivedFinal : public Final
{
};
int main()
{
DerivedFinal df;
}
The above code does not compile and gives error in VC++ as follows
error C2248: 'FinalBase::FinalBase' : cannot access private member
declared in class 'FinalBase'.
If I remove the keyword virtual while inheriting from the FinalBase.
The code compiles without any error ... Any comments on this ???
-Amol
where it can't be further derived but instatiated. So I search the net
and found to do so. Make a base class which has constructor private.
And a Final class inheriting from it privately.
// Code snippet
class FinalBase
{
FinalBase() {}
friend class Final;
};
class Final : virtual private FinalBase
{
public:
};
class DerivedFinal : public Final
{
};
int main()
{
DerivedFinal df;
}
The above code does not compile and gives error in VC++ as follows
error C2248: 'FinalBase::FinalBase' : cannot access private member
declared in class 'FinalBase'.
If I remove the keyword virtual while inheriting from the FinalBase.
The code compiles without any error ... Any comments on this ???
-Amol