【问题标题】:error: ‘cast’ does not name a type void setCastDescription(std::string desc) cast.description = desc; } [closed]错误:'cast' 没有命名类型 void setCastDescription(std::string desc) cast.description = desc; } [关闭]
【发布时间】:2019-02-07 06:28:51
【问题描述】:
player.h:155:43: error: expected ‘;’ at end of member declaration
   void setCastDescription(std::string desc) cast.description = desc; }

player.h:155:45: error: ‘cast’ does not name a type
   void setCastDescription(std::string desc) cast.description = desc; }

player.h: In member function ‘bool Player::getCastingState() const’:
player.h:148:39: error: ‘cast’ was not declared in this scope
  bool getCastingState() const {return cast.isCasting; };
                                       ^

player.h: In member function ‘virtual const string& Player::getCastingPassword() const’:
player.h:149:65: error: ‘cast’ was not declared in this scope
  virtual const std::string & getCastingPassword() const {return cast.password; };
                                                                 ^

player.h: In member function ‘PlayerCast Player::getCast()’:
player.h:150:31: error: ‘cast’ was not declared in this scope
  PlayerCast getCast() {return cast; }
                               ^

player.h: In member function ‘void Player::setCastPassword(std::string)’:
player.h:153:39: error: ‘cast’ was not declared in this scope
  void setCastPassword(std::string p) {cast.password = p; };
                                       ^

player.h: At global scope:
player.h:156:28: error: expected initializer before ‘&’ token
  virtual const std::string & getCastDescription() const return cast.description; }
                            ^

player.h:156:82: error: expected declaration before ‘}’ token
  virtual const std::string & getCastDescription() const return cast.description; }
                                                                                  ^

这是我试图编译的代码。它非常大,所以我只会发布出现错误的行...

bool getCastingState() const {return cast.isCasting; };
virtual const std::string & getCastingPassword() const {return cast.password; };
PlayerCast getCast() {return cast; }

void setCasting(bool c);
void setCastPassword(std::string p) {cast.password = p; };

void setCastDescription(std::string desc) cast.description = desc; }
virtual const std::string & getCastDescription() const return cast.description; }

我已经到处搜索以找到类似的东西,但从昨天开始我没有得到任何东西,我正在寻找解决方案,我希望这里有人可以帮助我

【问题讨论】:

  • 您发布的 sn-p 的最后两行缺少左大括号。
  • @JesperJuhl 我怎么能做到这一点?如果你看到我发布了代码,我是新手,如果我问了太多问题,我很抱歉

标签: c++ error-code


【解决方案1】:

您缺少演员描述的 getter 和 setter 的左括号:

void setCastDescription(std::string desc) cast.description = desc; }
                                          ^
virtual const std::string & getCastDescription() const return cast.description; }
                                                       ^

【讨论】:

  • 我不知道你所说的缺少 getter 和 setter 是什么意思
  • 我没有写“缺少 getter 和 setter”。我写了“缺少左括号”。如果您没有看到这里有什么问题,即使^ 标记缺少括号,您也需要停止编码 "large code" 正如您自己所说的那样,并学习基础知识,例如what are functionswhat are curly brackets for.
  • 你说得对,也许我应该停止编码,谢谢你的回答......祝你有美好的一天
  • 很抱歉,如果我希望你停止编码或学习编码。我只是说,如果您从 “大型代码” 开始,您并没有帮自己一个忙。从小处着手。学习基础知识。然后慢慢尝试更大的项目。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-08
  • 1970-01-01
  • 1970-01-01
  • 2018-12-09
  • 2014-09-21
  • 2014-08-25
相关资源
最近更新 更多