What is virtual class and friend class?

Showing Answers 1 - 1 of 1 Answers

samiksc

  • Jan 24th, 2006
 

Virtual Base Class: Used in context of multiple inheritance in C++. If you plan to derive two classes from a class, and further derive one class from the two classes in the second level, you need to declare the uppermost base class as 'virtual' in the inherited classes. This prevents multiple copies of the uppermost base class data members when an object of the class at the third level of hierarchy is created.

Friend class: When a class declares another class as its friend, it is giving complete access to all its data and methods including private and protected data and methods to the friend class member methods.

Friendship is not bi-directional. If A declares B as its friend it does NOT mean that A can access private data of B. It only means that B can access all data of A.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions