Do structures support inheritance? I think it's stupid question, but I have not much idea about it.
What is the meaning of writing code like this:
struct A {
void f() { cout << "Class A" << endl; }
};
struct B: A {
void f() { cout << "Class B" << endl; }
};
In structures also private section will come, don't they give encapsulation? What is the major difference between structures and classes?
Yes structures support all features that classes do. The differences are:
- structure inheritance is public by default
- structure members are public by default
Structures are classes with default visibility public. Everything else is equal.
In C++ only difference between a structure and a class is that for structure the method/member variable visibility is public by default and for class it is private by default. Other than that there is no difference.