#include <iostream>
#include <vector>
using namespace std;
class Base
{
public:
void Display(void)
{
cout<<"Base display"<<endl;
}
int Display(int a)
{
cout<<"Base int display"<<endl;
return 0;
}
};
class Derived : public Base
{
public:
void Display(void)
{
cout<<"Derived display"<<endl;
}
};
void main()
{
Derived obj;
obj.Display();
obj.Display(10);
}
$test1.cpp: In function ‘int main()’:
test1.cpp:35: error: no matching function for call to ‘Derived::Display(int)’
test1.cpp:24: note: candidates are: void Derived::Display()
在注释掉obj.Display(10)
,它的工作原理。下面的代码有什么问题?这不是编译
您正在使用什么编译器?它看起来像'gcc',但这是最近的代码吗?为什么你得到'$ test1.cpp:在函数'int main()':'中,即使你将main定义为void main()'?用gcc和vC++试用了 – Muggen 2011-03-17 08:09:49
。从vC++编辑器复制代码,粘贴gcc输出。 – 2011-03-17 08:14:11