Klasa:Zagnieżdżone klasy szablonu specjalizacji
template<typename C, typename T>
class A
{
template <typename U>
class Nested{};
Nested<T> n;
};
I chcę się specjalizować Nested
. Oto, co starałem:
template<typename C, typename T>
class A
{
template <typename U>
class Nested{};
template <>
class Nested<int>{}; // by my logic this should work by I have a compilation error "explicit specialization in non-namespace scope 'class A<C, T>'"
Nested<T> n;
};
moja następna próba:
template<typename C, typename T>
class A
{
template <typename U>
class Nested{};
Nested<T> n;
};
template<>
A<>::Nested<int>{}; // What is the correct syntax to do it here? Now I have an error "wrong number of template arguments (0, should be 2)"
tutaj na stackoverflow znalazłem rozwiązanie:
template<typename C, typename T>
class A
{
template <typename U, bool Dummy = true>
class Nested{}; // why need of this Dummy??
template <bool Dummy>
class Nested<int, Dummy>{}; // why need to provide an argument??
Nested<T> n;
};
To doskonale działa, ale nie mogę zrozumieć, jak to zrobić. Dlaczego podać fałszywy argument szablonu? Dlaczego nie mogę używać surowej specjalizacji template<> class Nested<int, true>{}
lub template<> class Nested<int>{}
?
Tak, ale nie działa na gcc i clang. Loos jak Microsoft nie przestrzega standardu. A może jest przełącznik kompilatora. – nikitablack