【发布时间】:2016-09-20 12:01:30
【问题描述】:
当我尝试编译由 CUDA 的 cudafe++ 工具生成的以下(损坏的)代码时,Visual Studio 会抛出错误 C2244。这是正确的行为吗? GCC 似乎并不关心签名不匹配。
代码:
template<int Size>
class MyClass {
public:
MyClass(const int data[Size]);
};
template<int Size>
MyClass<Size> ::MyClass(const int data[]) {}
void func(MyClass<4> input) {}
输出:
test2.cpp(9) : error C2244: 'MyClass<Size>::MyClass' : unable to match function definition to an existing declaration
test2.cpp(5) : see declaration of 'MyClass<Size>::MyClass'
definition
'MyClass<Size>::MyClass(const int [])'
existing declarations
'MyClass<Size>::MyClass(const int [Size])'
【问题讨论】:
-
在参数中,
const int data[Size]、const int data[]和const int *data是等价的。也许 MSVC++ 有一个“一个声明规则”(作为the one definition rule 的变体,它表示“每个定义都由相同的标记序列组成”)。但是,声明不应该是这种情况,只有定义。 -
在我看来就像 VC++ 中的一个错误。
标签: c++ arrays visual-c++ cuda