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);
}
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);
}