In java a final class is a class that cannot be derived. How
can you make a similar class in C++
Answer / cpp master
Using virtual base classes. The most derived class has to
initialize all the virtual base class in the inheritance
hierarchy. To make such a class simply create a empty class
with a private constructor and mark the class to be made
non derivable as the friend of that class. Now simply
public virtually derive the non derivable with the empty
class. Below is the example code:
class UnDerivable;
class dummy{
private:
dummy(){}
friend class UnDerivable;
};
class UnDerivable: virtual public dummy
{
};
//try deriving fro the underivable class
class deriveUnderivable:public UnDerivable
{
};
int main()
{
UnDerivable ud;
deriveUnderivable uud; //will give an error
return 0;
}
Is This Answer Correct ? | 1 Yes | 0 No |
What is the handle class?
What is boyce codd normal form in c++?
How do you traverse a btree in backward in-order?
What is the Diffrence between a "assignment operator" and a "copy constructor"?
Which operations are permitted on pointers?
Is swift faster than c++?
What is the difference between strcpy() and strncpy()?
What are the different types of polymorphism in c++?
Is there structure in c++?
Is C++ case sensitive a) False b) Depends on implementation c) True
What are containers in c++?
Mention the storage classes in c++.