我正在阅读这个问题和其他一些东西:Are there cases where a typedef is absolutely necessary??模板转换操作符returing对数组的引用
我写了这个代码:C++ 11的
const int arrayOfInt[10] = {0};
template<typename T, int N> using X = const T (&)[N];
struct foo
{
template<typename T, int N> operator X<int,10>() { return arrayOfInt; }
};
void bar(const int (&) [10]) {}
int main()
{
bar(foo());
return 0;
}
using
功能不是为我工作,也是我无法想象如何typedef
在这种情况下,返回类型也因为我的foo
类不是模板本身。我需要看到解决方案使用using
关键字和typedef
都。非常感谢真棒的人们:)
它不应该是'运营商X'? –
请始终在您说某些内容不工作时,发布实际的编译器错误消息。 – Petr
@KerrekSB爱你:),谢谢你帮助我们noobs :) –