Tuesday, October 18, 2005

Re: New kid in the block


Hi Ashutosh,

The question you asked is just like implementing the functionality as
Final class in java.
C++ don't have direct keyword but has the means to implement this
functionality.

Idea is if you derive(virtual public) a class from another class having
private constructors, you cannot create an object of derived class.

To avoid this you need to declare derived (Final class) class as friend
of base class. So that now if some one tries to inherit from this Final
class, compilation gives error as this class cannot call constructor of
its super class i.e. Final class's super class i.e. base class that has
private constructor.

just see the example code given below.

class Temp
{
private:
~Temp() { };
friend class FinalClass;
};

class FinalClass : virtual public Temp
{
. . .
};

Hope this will serve your purpose.

join CPP Sucks at "Cpp-Sucks@googlegroups.com" and also invite your
friends to joins this also to have healthy discussion on C++.

Regards,
Bhupinder Singh.

ashutosh verma wrote:
> hi to all,
> I am new to the group. & i've just read the topics there & i found that my
> knowledge about C++ & Oops is like a drop in the ocean. Means you guys are
> master of this language. would you please recommend me the book, i should
> read which covers the topic like:-
> "how we can initialize a class such that no class can be derived from it,
> further etc." like which also tell about the realastic approach to the
> properties of every topic in C++.
> I have referred *Robert Lafore* in Oops. What else i should reffer.
> Please Reply.

0 Comments:

Post a Comment

<< Home