在 c++ 中定义一个空构造函数
Define an empty constructor in c++
In main.cpp
LLC* llc = new LLC();
这是 llc 中的构造函数.cpp
LLC::LLC() :
{
cout<<"test"<<endl;
}
这是我得到的错误:
llc.cpp(36): error: expected an identifier
{
^
我犯了什么错误?构造函数在 llc 头文件中的类 LLC 的公共部分中给出.cpp
LLC::LLC() :
{
cout<<"test"<<endl;
}
应该是
LLC::LLC()
{
cout<<"test"<<endl;
}
通过添加 :
在构造函数中指定成员初始化列表。这就是为什么编译器期望在那里有一个标识符。如果您不打算初始化其中的任何成员,则应删除该:
。
LLC::LLC() // Absense of :
{
cout<<"test"<<endl;
}
相关文章:
- 如何使用 swig 修改类构造函数以保留对其中一个构造函数参数的引用?
- 为什么从另一个构造函数内部调用C++构造函数不修改类变量?
- 如何处理没有默认构造函数但在另一个构造函数中构造的对象?
- 我用字符串做了一个C++构造函数,但它不会打印出字符串
- 有一个构造函数,但有两个析构函数
- C++ 如何根据作为输入传递的参数调用一个构造函数或另一个构造函数?
- C 如何仅实现多个继承类的一个构造函数
- 错误:在“(”标记之前进行预期的构造函数、析构函数或类型转换.即使我有一个构造函数
- 让构造函数在其初始化列表中调用同一类的另一个构造函数是否有效
- 创建一个构造函数,即Capabe获取任何数量的参数
- 我如何在类上需要另一个构造函数的对象中声明一个对象
- 使用委托调用构造函数和在另一个构造函数体中调用的区别
- 为什么当我尝试编译时,我的 c++ 代码不断返回对我的一个构造函数的"未定义的引用"?
- C :另一个构造函数的构造函数的隐式调用
- 如何创建一个构造函数,该构造函数吸收char阵列
- 为什么有一个构造函数同时接受initializer_list和一个参数包
- 我有一个构造函数,但我需要将输出返回到 main.cpp.我无法使用获取字符串功能!!任何想法如何实现这一目标?
- 如何在一个构造函数中使用两个可变参数模板参数来绑定两个函数
- 从同一类的另一个构造函数调用构造函数
- 将类的实例传递给另一个构造函数,该构造函数将其对象添加到所传递实例所拥有的列表中