Yes, this is the case:
Code:
#include <iostream>
#include <string>
//- using std::string;
using std::endl;
using std::cout;
using std::cin;
//- class A
{
public:
A::A() : theString("A") {}
protected:
string theString;
};
class B
{
public:
B::B() : theString("B") {}
private:
string theString;
};
class C : public A , public B
{
public:
void print()
{
cout<<theString<<endl;
}
};
int main()
{
C theC;
theC.print();
cin.get();
return 0;
} And will error indeed.
Let's see how this looks in memory:
Code:
CLASS A string theString;
CLASS B string theString;
CLASS C void print
As you can see, internally the system doesn't care about access specifiers. Public, private, all the same memory wise. But it does know what member belongs to what class. And here lies our solution: We need to tell the system which one we mean.
Use the
scope resolution operator "::" Code:
class C : public A , public B
{
public:
void print()
{
cout<<A::theString<<endl;
}
}; Or formally:
Access specifiers do not play a role in name lookup resolution.
That was another good question.