2
我正在嘗試在類Application
中創建一個LLVMContext
成員變量。 MCVE:LLVMContext作爲類成員會破壞構造函數嗎?
#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);
}
添加變量,但是,產生一些非常奇怪的錯誤:(4.0.1鏘和蘋果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個」)?
天哪。謝謝。我非常想到在類定義中發現一個錯誤,我完全忽略了這一點。 – idmean