3

可能重复:
奇怪的 VC++ 编译错误,C2244

我有以下带有模板结构和模板成员函数的 C++ 代码。模板函数在其声明中使用模板参数。代码无法编译。

template<typename MyType>
struct Network
{
    template<typename MyOtherType>
    void Do_Stuff(char param[MyOtherType::size]);
};

template<typename MyType>
template<typename MyOtherType>
void Network<MyType>::Do_Stuff(char param[MyOtherType::size])
{
};

struct Array_Size
{
    static const int size;
};

const int Array_Size::size=3;

int main()
{
}

Visual Studio 2010 生成以下错误:

error C2244: 'Network<MyType>::Do_Stuff' : unable to match function definition to an existing declaration
    definition
    'void Network<MyType>::Do_Stuff(char [MyOtherType::size])'
    existing declarations
    'void Network<MyType>::Do_Stuff(char [MyOtherType::size])'

我不明白为什么即使定义和声明相同,编译器也找不到匹配项。

4

0 回答 0