Overriding overloaded functions?

  • Thread starter Generic Usenet Account
  • Start date
G

Generic Usenet Account

The code example below fails to compile under g++ and Solaris native
CC and gives the following output:

"main.cc", line 12: Warning: derived::func hides the virtual function
base::func(int).
"main.cc", line 36: Error: Too few arguments in call to
"derived::func(int, int)".
1 Error(s) and 1 Warning(s) detected.

Why would overriding the function 'int func(int a, int b)' in the
derived class make the overriden function 'int func(int a)' in the
base class not visible?

Thanks in advance for your help.

Tom Helfand

----- Begin main.cc -----

#include <iostream.h>

class base {
public:
virtual void func(int a);
virtual int func(int a, int b);
};

class derived : public base {
public:
int func(int a, int b);
};

void
base::func(int a) {
cout << "base::func(int a)" << endl;
}

int
base::func(int a, int b) {
cout << "base::func(int a, int b)\n" << endl;
return 0;
}

int
derived::func(int a, int b) {
cout << "derived::func(int a, int b)\n" << endl;
return 0;
}


int
main(int argc, char * argv[]) {
derived *instance = new derived();

instance->func(1);
instance->func(1,2);
}
 
R

Russell Hanneken

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top