Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

In java a final class is a class that cannot be derived. How
can you make a similar class in C++

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is array in c++ pdf?

1165


Differentiate between a constructor and a destructor in c++.

1006


What is oops in c++?

1050


What does it mean to declare a member function as virtual?

1061


What is :: operator in c++?

1037


Is overriding possible in c++?

994


How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Why is it difficult to store linked list in an array?how can you find the nodes with repetetive data in a linked list?

1271


What are the general quetions are in DEna bank manager IT/System interviews?

2003


What is object in c++ example?

1094


Explain the difference between static and dynamic binding of functions?

1051


What is a c++ map?

1375


What is an incomplete type in c++?

1264


What is atoi?

963


Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?

1060


What is the difference between new() and malloc()?

2038