Olası Çoğalt:
Function with same name but different signature in derived classBasit C++ Kalıtım Örneği, Sorun nedir?
Bunu derlemek çalışıyorum ve ben koduyla yanlış anlamaya olamaz. Xcode g ++ sürüm 4.2.1 ile MacOSX Snow Leopard kullanıyorum. Birisi bana sorunun ne olduğunu söyleyebilir mi? Bunun bir derlemesi gerektiğini düşünüyorum. Ve bu benim ev ödevim değil, bir geliştiriciyim ... en azından ben bununla uğraşana kadar olduğumu düşündüm. İşte
error: no matching function for call to ‘Child::func(std::string&)’
note: candidates are: virtual void Child::func()
kodudur:
#include <string>
using namespace std;
class Parent
{
public:
Parent(){}
virtual ~Parent(){}
void set(string s){this->str = s;}
virtual void func(){cout << "Parent::func(" << this->str << ")" << endl;}
virtual void func(string& s){this->str = s; this->func();}
protected:
string str;
};
class Child : public Parent
{
public:
Child():Parent(){}
virtual ~Child(){}
virtual void func(){cout << "Child::func(" << this->str << ")" << endl;}
};
class GrandChild : public Child
{
public:
GrandChild():Child(){}
virtual ~GrandChild(){}
virtual void func(){cout << "GrandChild::func(" << this->str << ")" << endl;}
};
int main(int argc, char* argv[])
{
string a = "a";
string b = "b";
Child o;
o.set(a);
o.func();
o.func(b);
return 0;
}
sadece bir saat başıbaşkasının bu sorunu vardı. com/questions/6034869/c-devriyesi – Nawaz