View Single Post
Old 04-15-2005, 11:43 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote