没有匹配的函数来调用

黄贵宝

我是CPP的新手,正在练习继承。我认为我的语法有问题,但我无法说出原因,这是我的代码的一部分:

#include<iostream>
using namespace std;

class Clown{
public:
  string name ;
  void dance();
  Clown(string s) {name = s;}


};


class CircusClown: public Clown{
public:
  string name;
  void dance();
  CircusClown(string s){name = s;}
};

我认为我的继承班出了点问题。

我正在使用Mac,因此显示有问题,但这是错误:

Clowns.cpp: In constructor â:
Clowns.cpp:18: error: no matching function for call to â
Clowns.cpp:8: note: candidates are: Clown::Clown(std::string)
Clowns.cpp:4: note:                 Clown::Clown(const Clown&)
LihO

当构造派生类时,还必须调用基类的构造函数。而且,由于您的基类(Clown)没有提供默认的构造函数,因此编译器不知道Clown应使用哪个构造函数。

在这种情况下,您需要Clown显式调用的构造函数。还要避免using namespace std;并考虑std::stringconst引用传递对象,而不是按值传递:

class CircusClown : public Clown {
public:
    std::string name;
    CircusClown(const std::string& s) : Clown(s), name(s) { }
};

有关更多信息,请参见调用超类构造函数的规则是什么?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

没有匹配的函数来调用“ getline”

没有匹配的函数来调用sort()

C ++:没有匹配的函数来调用

没有匹配的函数来调用“strlen”

没有匹配的函数来调用类构造函数

没有匹配的函数来调用类中的成员函数

没有匹配的函数来调用'std :: advance'错误

sort()-没有匹配的函数来调用'swap'

没有匹配的函数来调用FMOD :: Studio :: System :: setListenerAttributes()

发生没有匹配的函数来调用C ++中的错误

没有匹配的函数来调用'regex_search(...)'

没有匹配的成员函数来调用“连接”-使用“ this”时

错误:没有匹配的函数来调用“ make_pair”

C ++-没有匹配的函数来调用'getaddrinfo'

没有匹配的函数来调用'begin(int **&)'

没有匹配的函数来调用“ make_shared”

C ++线程-没有匹配的函数来调用

没有匹配的函数来调用“连接”(QT)

没有匹配的函数来调用“点”和“反射”

运算符>>错误:没有匹配的函数来调用

没有匹配的函数来调用“ myclass :: myclass()”

没有匹配的函数来调用A :: A(MainWindow * const)

C ++错误::没有匹配的函数来调用'function'

“不是...的成员”和“没有匹配的函数来调用”错误

C ++错误:没有匹配的函数来调用'print_size'

没有匹配的函数来调用'const RadioMap :: comp'类型的对象

Qt错误:错误:没有匹配的函数来调用“ QHBoxLayout :: addItem(QPushButton *&)”

C ++没有匹配函数来调用向量push_back

C ++ Boost Geometry错误:没有匹配的函数来调用“ assertion_failed”