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++



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

Post New Answer

More C++ General Interview Questions

Explain the extern storage classes in c++.

0 Answers  


How did c++ get its name?

0 Answers  


What is difference between initialization and assignment?

12 Answers   HCL, HP, Infosys,


What are different types of polymorphism supported by C++

2 Answers   CA, GameLoft,


What is a pointer with example?

0 Answers  


How do you save a c++ program?

0 Answers  


What is double in c++?

0 Answers  


Which one between if-else and switch is more efficient?

0 Answers  


Out of fgets() and gets() which function is safe to use and why?

0 Answers  


What problems might the following macro bring to the application?

0 Answers  


What are the advantages of using a pointer? Define the operators that can be used with a pointer.

0 Answers  


Why are pointers used?

0 Answers  


Categories