【发布时间】:2011-03-17 16:22:58
【问题描述】:
#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,但这是最新的代码吗?为什么即使您已将 main 定义为void main(),您也会得到$test1.cpp: In function ‘int main()’:? -
尝试使用 gcc 和 vc++。从 vc++ 编辑器复制代码,粘贴 gcc 输出。
标签: c++