Overload in Child - Denied!

P

Peteroid

Ok, what am I do wrong here. I created a class with a public method, and
when I try to create a new overload of it in a derived child class it won't
let me:

class Parent_Class
{
public:
long Method( const long x ) {}
} ;

typedef std::pair<long,long> coords ;

class Child_Class : public Parent_Class
{
public:
long Method( const coords c ) {} // *error*
} ;

The error is something like "can't convert coords into a long", which looks
like it is interpretting the child version as a 'calling' of the parent
method instead of a 'new overload definition' with a different parameter
type. So, what is the problem here?

[==Peteroid==]
 
C

Carl Daniel [VC++ MVP]

Peteroid said:
The error is something like "can't convert coords into a long", which
looks like it is interpretting the child version as a 'calling' of
the parent method instead of a 'new overload definition' with a
different parameter type. So, what is the problem here?

How 'bout posting an actual bit of code that fails and the actual error
message you received?

I'm going to guess that your problem is that the funciton in the child class
is trying to call the version in the base class and is doing so using an
unqualified name, expecting that overload resolution will pick the parent
function. Problem is, these functions don't overload. If the child needs
to call the parent version, it must call it with a qualified name:
Parent_Class::Method().

-cd
 

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

Top