For the first question, access modifiers you use when inheriting classes specify the maximum level of visibility of the members of the base class.
If there are two classes, a base class B and a derived class A, then:
When public inheritance is used, all base class functions can be used in class A, in classes derived from A and outside of class A.
When protected inheritance is used, all base class functions can be used in class A and in classes derived from A, but not outside of those classes.
When private inheritance is used, all base class functions can be used in class A, but not in derived classes or outside class A.
A quick example. If you say that class A inherits class B, what you're actually saying is that class A has all its own members plus those of class B. Such as the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
class B {
public:
doSomethingPublic();
protected:
doSomethingProtected();
private:
doSomethingPrivate();
}
class A : public B {
public:
bar();
}
|
Here, class A uses public inheritance to inherit from class B. This means that whenever class A is used, all the methods that are specified in class B can be used on A as well. For example, the following code would work:
1 2
|
A foo;
foo.doSomethingPublic();
|
However, say that the protected access modifier was used to inherit from B. Then, the code above would not compile, since the maximum level of visibility is protected, and doSomethingPublic() is a public function. However, in that scenario, classes that derive from A would still be able to use doSomethingPublic() internally.
If the private access modifier were used to inherit from B, class A could use doSomethingPublic() in its own functions, but no other code could access that function.
So, when inheriting with an access modifier, you're actually saying, all of the functions & variables of the class I'm inheriting are now members of the derived class as well, and any members which are more visible than the access modifier will be set to the visibility of the access modifier.
As for your second question, the Diamond refers to the scenario where you have 4 classes, where class B and C inherit from class A, and class D inherits from both B and C. This leads to all kinds of ambiguity problems, since class D inherits class A's functions from two difference places, and thus the compiler cannot decide which to use. A comprehensive explanation can best be found on Wikipedia here:
https://en.wikipedia.org/wiki/Multiple_inheritance#The_diamond_problem