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 |
We all know that a const variable needs to be initialized at the time of declaration. Then how come the program given below runs properly even when we have not initialized p?
If a base class is an adt, and it has three pure virtual functions, how many of these functions must be overridden in its derived classes?
Define private, protected and public access control.
How do you invoke a base member function from a derived class in which you have not overridden that function?
What are keywords in c++?
How to construct virtual constructor
6 Answers CIStems Software, Symphony,
When is a template a better solution than a base class?
What is polymorphism & list its types in c++?
Explain the static storage classes in c++.
1.what is the difference between software & package &application.
How the endl and setw manipulator works?
Explain class invariant.