c++ - 编译错误: invalid conversion when calling base-type constructor

标签 c++ c++11 templates compiler-errors mingw-w64

我正在尝试在 MinGW-64 lljvm 下编译,这是一个不太大的程序。但我陷入了一个让我发疯的错误。

代码如下:

后端.h

class JVMWritter {
...
static char id;
...
};

后端.cpp
char JVMWriter::id = 0;

JVMWriter::JVMWriter(): FunctionPass(&id) {}

现在, FunctionPass 在 Pass.h 中声明如下:

通行证.h
class FunctionPass {
...
explicit FunctionPass (char &pid) : <initialization here> {}
...
};

当我尝试编译它时,我不断收到以下错误:
backend.cpp:39:16: error: invalid conversion from 'char*' to 'char' [-fpermissive]
   FunctionPass(&JVMWriter::id), targetData(td), out(o), classname(cls), debug(dbg) {
                ^~~~~~~~~~

In file included from D:/dev/msys64/mingw64/include/llvm/IR/DataLayout.h:27:0,
                 from D:/dev/msys64/mingw64/include/llvm/IR/Module.h:20,
                 from D:/dev/msys64/mingw64/include/llvm/IR/PassManager.h:46,
                 from D:/dev/msys64/mingw64/include/llvm/Analysis/LoopInfo.h:47,
                 from backend.h:29,
                 from backend.cpp:23:
D:/dev/msys64/mingw64/include/llvm/Pass.h:300:12: note:   initializing argument 1 of 'llvm::FunctionPass::FunctionPass(char&)'
   explicit FunctionPass(char &pid) : Pass(PT_Function, pid) {}
            ^~~~~~~~~~~~

backend.cpp:39:16: error: cannot bind rvalue '(char)(& JVMWriter::id)' to 'char&'
   FunctionPass(&JVMWriter::id), targetData(td), out(o), classname(cls), debug(dbg) {
                ^~~~~~~~~~

In file included from D:/dev/msys64/mingw64/include/llvm/Pass.h:388:0,
                 from D:/dev/msys64/mingw64/include/llvm/IR/DataLayout.h:27,
                 from D:/dev/msys64/mingw64/include/llvm/IR/Module.h:20,
                 from D:/dev/msys64/mingw64/include/llvm/IR/PassManager.h:46,
                 from D:/dev/msys64/mingw64/include/llvm/Analysis/LoopInfo.h:47,
                 from backend.h:29,
                 from backend.cpp:23:
D:/dev/msys64/mingw64/include/llvm/PassAnalysisSupport.h: In instantiation of 'llvm::AnalysisUsage& llvm::AnalysisUsage::addRequired() [with PassClass = llvm::LoopInfo]':

backend.cpp:52:27:   required from here
D:/dev/msys64/mingw64/include/llvm/PassAnalysisSupport.h:61:39: error: 'ID' is not a member of 'llvm::LoopInfo'
     return addRequiredID(PassClass::ID);

我明显的问题:为什么提示我正在尝试无效的转换?我在这些片段中看不到这样的尝试。

最佳答案

char & pid声明 pid作为引用 char , 当你通过 &id这是指向 char 的指针.

关于c++ - 编译错误: invalid conversion when calling base-type constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44372972/

相关文章:

c++ - 如何在初始化列表中创建一个非空的 boost ublas::vector?

c++ - 如何检查当前是否用鼠标单击了小部件?

c++ - 单例行为相关查询

C++ 函数模板 : Derived and explicit return type

c++ - 我应该如何在嵌套类中正确使用友元声明?

c++ - 寻找最大允许值的模板方法

c++ - 在 AngelScript 中注册一个 C++ 类并传递一个类实例

c++ - 移位寄存器74HC595输出电流

c++ - 在 C++ 中是否可以使用多个 dlopen 处理程序

c++ - 可变参数模板作为 std::function 的参数