How to make the class cannot be inherited
In below example, class Final cannot be inherited by any other class
class temp
{
private:
~temp(){}
public:
temp(){}
friend class Final;//make final class can access the destructor
};
class Final: virtual public temp
{
public:
Final(){}
};
class Final2: virtual public Final
{
public:
Final2(){}
};
int main()
{
//temp t; //you cannot create a object for temp because the destructor is private
Final f; //you can create the object of Final class
//Final2 f2;//you cannot inherit the Final class
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment