以下代碼被gcc,vC++和clang接受。是否使用C++標準定義變量?A <int> :: template B <int> x;`?
template<class T>
struct A
{
template<class U>
struct B
{};
};
int main()
{
A<int>::B<int> y; // OK as expected
A<int>::template B<int> x; // Also OK! Is this standard-compliant?
};
使用A<int>::template B<int> x;
是否符合C++標準定義變量?
B是一個依賴於模板的類型模板,所以第二個語法是完全正確的。 – Quentin
您能否將我引薦至指定此用法的標準頁面?謝謝。 – xmllmx
@peppe不是重複的,因爲你不需要在這裏使用'template'。 – juanchopanza