#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