我试图编写一个特征来检测任意类型是否为它定义了插入运算符。为此,我希望使用std :: is_same <>来比较函数指针的类型和预期的类型。我具有由下面的代码以运算符的地址<<在gcc中失败4.8
#include <iostream>
class A {};
std::ostream& operator<<(std::ostream& os, const A& a)
{
return os;
}
int main()
{
decltype(static_cast<std::ostream&(*)(ostream&, const A&)>(&operator<<)) foo = nullptr;
std::cout << foo << std::endl;
return 0;
}
在GCC 4.8表现出一个问题,--std = C++ 11
test2.cpp:12:81: error: expected primary-expression before ')' token
decltype(static_cast<std::ostream&(*)(std::ostream&, const A&)>(&::operator<<)) foo = nullptr;
^
错误没有出现在铛或更近的gcc版本然而为了生产我们必须能够在gcc 4.8中编译。 GCC 4.8有没有解决这个问题的方法?
思想,这个问题可能是相同的作为http://stackoverflow.com/q/23061912/560648,但它不是,所以我不知道为什么我写这个评论 –
我假设问题是与运算符<<而不是指针类型。 –