llvmcontext作为类成员断路构造函数
LLVMContext as class member breaks constructors?
我正在尝试在Application
类中制作LLVMContext
成员变量。MCVE:
#include <llvm/IR/LLVMContext.h>
struct Foo {};
class Application {
public:
Application(int a, Foo foo, int b);
private:
llvm::LLVMContext context_;
};
void function() {
auto application = Application(12, Foo(), 21);
}
添加变量会产生一些非常奇怪的错误:( Clang 4.0.1和Apple LLVM版本8.1.0)
toy.cpp:13:8: error: no matching constructor for initialization of 'Application' auto application = Application(12, Foo(), 21); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ toy.cpp:5:7: note: candidate constructor (the implicit copy constructor) not viable: expects an l-value for 1st argument class Application { ^ toy.cpp:7:3: note: candidate constructor not viable: requires 3 arguments, but 1 was provided Application(int a, Foo foo, int b); ^ 1 error generated.
这里发生了什么?为什么Clang认为我试图使用一个参数的构造函数("但是提供了1个")?
llvm::LLVMContext
不是可复制的类。它是从文档中删除的副本。
LLVMContext (LLVMContext &) = delete
由于您确实复制了初始化,因此编译器必须检查您的班级有一个可行的副本。但这是由于llvm::LLVMContext
的隐式删除。
除非您使用的是C 17,否则保证了复印件并可以避免支票,只需摆脱auto
类型声明:
Application application {12, Foo(), 21};
相关文章:
- "error: no matching function for call to"构造函数错误
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 选择要调用的构造函数
- 如何委托派生类使用其父构造函数?
- 构造函数正在调用一个使用当前类类型的函数
- 没有用于初始化C++中的变量模板的匹配构造函数
- 初始化具有非默认构造函数的std::数组项的更好方法
- 当从函数参数中的临时值调用复制构造函数时
- 在c++构造函数中使用随机字符串生成器
- 一对向量构造函数:初始值设定项列表与显式构造
- 从构造函数抛出异常时如何克服内存泄漏
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 继承:构造函数,初始化C++11中基类的类C数组成员
- 具有默认模板类型的默认构造函数的类型推导
- 使用dynamic_cast和构造函数时出错
- 在c++中使用向量时,如何调用构造函数和析构函数
- llvmcontext作为类成员断路构造函数