P
PengYu.UT
The following program shows that virtual function can not be
overloaded.
Could you tell me the reasons from the C++ compiler point of view?
Thanks!
Peng
#include <iostream>
class B{
public:
virtual void doit(){
std::cout << "in B" << std::endl;
}
void doit(int i){
std::cout << i << std::endl;
doit();
}
};
class D: public B{
public:
virtual void doit(){
std::cout << "in D" << std::endl;
}
};
int main(int argc, char *argv[]) {
D d;
d.doit(1);
}
overloaded.
Could you tell me the reasons from the C++ compiler point of view?
Thanks!
Peng
#include <iostream>
class B{
public:
virtual void doit(){
std::cout << "in B" << std::endl;
}
void doit(int i){
std::cout << i << std::endl;
doit();
}
};
class D: public B{
public:
virtual void doit(){
std::cout << "in D" << std::endl;
}
};
int main(int argc, char *argv[]) {
D d;
d.doit(1);
}