小编Ton*_*ony的帖子

char*和char [N]的模糊错误

有人可以帮助我理解这是否是正确的行为.

考虑这个例子:

#include <iostream>
using namespace std;

template <typename T>
struct test {
};

template <typename T>
bool operator==(const test<T>& obj, const T* arr) {
    return true;
}

template <typename T, size_t TN>
bool operator==(const test<T>& obj, const T (&arr)[TN]) {
    return false;
}

int main() {
    cout << ( test<char>() == "string" ) <<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用gcc 4.7.3,它可以很好地编译并按预期输出"0".

但是使用Visual Studio编译器会报告ambiguous error (C2593).

在这种情况下谁是对的,对此有什么standard看法?

谢谢.

c++ templates

8
推荐指数
1
解决办法
423
查看次数

标签 统计

c++ ×1

templates ×1