我正在閱讀這個問題和其他一些東西: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 :) –