我想知道爲什麼會出現在下面的函數的錯誤:錯誤C2660:「阿壩:: F」:函數不接受0參數
#include<iostream>
using namespace std;
class Saba
{
public:
Saba(){ cout << "Saba Ctor" << endl; }
Saba(const Saba& a){ cout << "Saba Copy Ctor" << endl; }
~Saba(){ cout << "Saba Dtor" << endl; }
virtual void f(){ cout << "Saba f()" << endl; }
virtual void g(){ cout << "Saba g()" << endl; }
void h(){ cout << "Saba h()" << endl; }
};
class Aba : public Saba
{
public:
Aba(){ cout << "Aba Ctor" << endl; }
Aba(const Aba& a){ cout << "Aba Copy Ctor" << endl; }
~Aba(){ cout << "Aba Dtor" << endl; }
virtual void g(){ cout << "Aba g()" << endl; }
virtual void f(int){ cout << "Aba f(int)" << endl; }
virtual void h(){ cout << "Aba h()" << endl; }
};
class Son : public Aba
{
public:
Son(){ cout << "Son Ctor" << endl; }
Son(const Son& a){ cout << "Son Copy Ctor" << endl; }
~Son(){ cout << "Son Dtor" << endl; }
void f(){ cout << "Son f()" << endl; }
void h(){ cout << "Son h()" << endl; }
};
int main()
{
Saba* sabaPtr = new Son();
Aba* abaPtr =dynamic_cast<Aba*>(sabaPtr);
abaPtr->f();
abaPtr->g();
abaPtr->h();
delete sabaPtr;
return 0;
}
我得到一個錯誤「錯誤C2660:「阿壩:: f':函數不接受0個參數「。但是從「saba」繼承的「aba」,所以他可以使用「saba」的f()
感謝您更正Tree With Eyes =) – Pumkko