小编rob*_*pop的帖子

方法定义的类型扣除与声明不匹配

我试图使用C++ 11/14的一些新功能,并且在他们的定义中遇到类型推导类方法的令人讨厌的事情.

场景:

// in header foo.hpp
class MyClass {
    T foo();
}

//in source foo.cpp
auto MyClass::foo() {
    return ... //something that returns T!
}
Run Code Online (Sandbox Code Playgroud)

对于T = cl_uint(OpenCL),这不起作用,编译器输出以下错误消息:

src/device.cpp:9:7:错误:'auto CL :: Device :: addressBits()const'的原型与类'CL :: Device'中的任何一个都不匹配

和

src/device.hpp:31:11:错误:候选者是:cl_uint CL :: Device :: addressBits()const

这与最新版本的GCC和Clang表现相同.具体的例子如下:

// in the .hpp
namespace CL {
    class Device : public Object<cl_device_id, cl_device_info, DeviceFunctions> {
    public:
        Device(cl_device_id id);

        cl_uint addressBits() const;

        // much more stuff ... (not of interest atm)
    }
}

// in the …
Run Code Online (Sandbox Code Playgroud)

c++ decltype auto type-deduction c++14

2
推荐指数
1
解决办法
80
查看次数

标签 统计

auto ×1

c++ ×1

c++14 ×1

decltype ×1

type-deduction ×1