answersLogoWhite

0


Best Answer

When you derive one class from another, the derived class inherits the sum of all the public and protected members exposed by the class it derives from. The underlying class is known as a base class and in the class hierarchy is an ancestor of the derived class. It is not necessary for the base class to know any of the details regarding its derivatives, as prudent use of virtual methods ensures the derived class acts correctly even when calling methods in the base class.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

Inheritance is where a class inherits from an existing class (a base class) to create a new class (a derived class). The derived class inherits all the public and protected members of its base class. The only caveat is that the base class MUST have a virtual destructor. Derived classes can also inherit from more than one base class.

Derived classes are said to be a "kind of" base class -- a more specialised version of the base class. This specialisation is achieved through virtual functions such that the derived class can override the base class virtual methods to provide more specialised behaviour. Base classes typically have one or more virtual methods in addition to the virtual destructor. Some base classes have nothing but virtual methods, however a method should only be made virtual if there's a need for that method to be overridden.

Note that derived classes can also act as base classes. The derived class need not declare its overrides as virtual (including its destructor) since they are implicitly virtual through inheritance. In C++11 and above (the latest standard) you can also add the override keyword to any method to clarify that it is a more specialised method of a base class method.

Base classes can also declare pure-virtual methods. These are the same as virtual methods except that the derived class must provide an implementation even if the base class provides a default implementation. Classes that declare pure-virtual methods are said to be abstract data types or abstract base classes, which means you cannot instantiate objects from them other than by derivation.

When a method is declared virtual (including the destructor) or pure-virtual, the most-derived override in the hierarchy is invoked, regardless of which object the method is invoked against.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is inheritance in visual c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Who developed visual c plus plus?

Microsoft developed Visual C++.


What is the brief history of visual c plus plus?

The complete history of Visual C++ can be found in the "Visual C++" article in Wikipedia.


Is Visual C or Visual C plus plus platform independent?

No, M$ Windoze only.


Is microsoft visual c plus plus the same as visual c plus plus?

Yes. Microsoft Visual C++ is the correct name, but it is often abbreviated to MSVC++ or just VC++. They are all the same.


Does c plus plus supports hierarchical inheritance?

Yes.


Can you make programs of C in visual c plus plus?

Yes.


Is visual studio c plus plus 2010 free?

No. Visual C++ Express is free, but Visual Studio C++ must be bought. The Express edition is a subset of the Studio release.


How ploymorphism and inheritance is different from that in Java and c plus plus?

C++ allows multiple inheritance while Java does not. In my opinion, multiple inheritance is not useful because it can get very confusing very quick. For polymorphism, C++ does early binding by default, while Java does late binding by default. Late binding is more useful than early binding.


How can you make a triangle in Visual C plus plus 2010?

Nevermind, I did it.


Visual c plus plus 6.0 free installer?

Visual C++ 6.0 is more than 16 years old. It is no longer available to buy and it was never available for free. The current version is Visual C++ 2013.


Which c plus plus best for vista?

Microsoft Visual C++ or Embarcadero C++ Builder (formally Borland C++ Builder).


Write a c plus plus programme to illustrate single inheritance?

struct A {}; // base class struct B : A {} // derived class (single inheritance).