我在从其父类(super class)是从模板创建的子类中声明构造函数时遇到问题。
示例代码如下所示:
template <class T>
class foo{
public:
foo();
};
typedef foo<double> foo_double;
class bar : public foo_double
{
bar() : foo_double();
};
int main(){
}
编译时出现错误:
In constructor ‘bar::bar()’:
expected ‘{’ at end of input
我在这里有点不知所措。
最佳答案
成员初始化列表只能与构造函数定义一起使用。所以你需要将它定义为
bar() : foo_double() {}
并且默认会默认构造基类,所以你根本不需要做。只是
bar() {}
关于c++ - 构造函数错误 : expected ‘{’ at end of input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36749287/