Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheritance Scope Problem 1

Status
Not open for further replies.

GameDude

Programmer
Jun 22, 2004
23
US
I have a class:

class Object
{
public:
LPTSTR getName();

private:
LPTSTR lpstr_ObjectName;
};

LPTSTR Object::getName()
{
return lpstr_ObjectName;
}

I have another class:

class SomeOtherClass : Object
{
public:
void doSomethingCool();
};

void SomeOtherClass::doSomethingCool()
{
if(getName() == <oneThing>)
//do something cool
else
//do something else cool
}

Now, this all looks good and everything. That is, until I compile it and get a scope error saying

<SomeOtherClass> isn't allowed to reference private/protected member <getName()> from class <Object>.

I'm not quite sure what to make of this, as the getName() function was explicitly defined as being public. I'm guessing I missed something in the "fine print" section of the C++ Manual here because it at least LOOKS like it should work.

Any suggestions?
 
Code:
class SomeOtherClass : public Object
Now it's true public inheritance, but w/o public keyword it was private inheritance by default...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top