【问题标题】:expected { before destructor预期 { 在析构函数之前
【发布时间】:2015-11-02 06:44:44
【问题描述】:

我的新课程名为 Fountainofyouth,我遇到了问题。尝试构建整个项目后调试器显示

warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]

和 错误:expected '{' before 'Fountainofyouth' 谁能告诉我发生了什么事? Fountainofyouth.cpp的内容:

#include "Fountainofyouth.h"

//warning
Fountainofyouth::Fountainofyouth(int startDrinks) : Field
{
    //ctor
}

//error
Fountainofyouth::~Fountainofyouth()
{
    //dtor
}

string Fountainofyouth::fieldType()
{
    return 0;
}

bool Fountainofyouth::canEnter(Unit* unit)
{
    return 0;
}

void Fountainofyouth::affect(Unit* unit)
{

}

`

【问题讨论】:

  • 知道Field是什么会有所帮助。

标签: c++ unit-testing c++11


【解决方案1】:

构造函数定义不应包含: Field 部分:

Fountainofyouth::Fountainofyouth(int startDrinks) // : Field <- remove this
{
    //ctor
}

如果您打算从 Field 继承 Fountainofyouth,请在类的定义中这样做,而不是在其构造函数中。

struct Fountainofyouth : Field
{
    // declaration of ctor, dtor, etc.
};

或者,如果FieldFountainofyouth 的成员,则为value initialize 添加一对括号:

Fountainofyouth::Fountainofyouth(int startDrinks) : Field()
{
}

【讨论】:

  • 或者,如果Field 是一个试图默认构造的变量,它应该是:Fountainofyouth(int startDrinks) : Field() { }
猜你喜欢
  • 2011-12-04
  • 2010-12-12
  • 2011-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多