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 c++ in english?
Who discovered c++?
write a program in c++ to generate imp z y x w v w x y z z y x w x y z z y x y z z y z z
write a program to add two numbers without using an arithmetic operator.
Tell me can a pure virtual function have an implementation?
What is c++ code?
How to tokenize a string in c++?
Explain the difference between c++ and java.
Write a C++ program that asks the user to choose a number between 1 and 1000. Then, your program should be able to guess the number by asking the user no more than 10 yes/no questions. Use a while loop in your program
Why c++ is created?
What is a dangling pointer?
Can we get the value of ios format flags?