Problem with overloading/inheritance/virtual methods

S

Simas Toleikis

Two classes:

class BaseClass
{
public:
virtual void Foo() = 0; // pure virtual here
virtual void Foo(int x);
};

class DerivedClass: public BaseClass
{
public:
void Foo();
};

When calling Foo(int) from DerivedClass pointer compiler cant see this
overload. Where is the problem?
 
V

Victor Bazarov

Simas said:
Two classes:

class BaseClass
{
public:
virtual void Foo() = 0; // pure virtual here
virtual void Foo(int x);
};

class DerivedClass: public BaseClass
{
public:
void Foo();
};

When calling Foo(int) from DerivedClass pointer compiler cant see this
overload. Where is the problem?

The "problem" is called "name hiding". It can be "solved" with the help
of 'using' declaration in DerivedClass:

class DerivedClass: public BaseClass
{
public:
using BaseClass::Foo; // brings all 'BaseClass' Foo in this scope
void Foo();
};


V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top