I have a little question to ask. I need to have an defitinition of what mean Inheritance and to have an example. I have the book of C ++ but do not have any proper expanation

Put simply, inheritance is saying that one class is a part of another class.:

class A {
public:
  void foo() { cout<<"foo\n"; }
};

class B: public A {};

You can create an object of B and call foo because A is a part of B. B is derived from A, a child of A, a subclass of A, or however you want to say it.

Much like you have the genes of your parents, B has the internals of A.

Inheritance means that one class derives all shared aspects with a higher more general class. For example I could have the class animal that might contain a few variables. If I made a class called dog that was derived from the animal class, it would also have common variables and function as the animal class. This prevents code replication.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.