c++.beta - explicit specialization of class template
- Christof Meerwald (61/61) Aug 22 2003 Hi,
Hi, #include <stdio.h> typedef int &r_type; typedef const r_type cr_type; template<class T> struct A { static const bool value = false; }; template<> struct A<int> { static const bool value = true; }; template<> struct A<const int> { static const bool value = true; }; template<> struct A<volatile int> { static const bool value = true; }; template<> struct A<const volatile int> { static const bool value = true; }; int main() { A<int> a1; printf("%d\n", a1.value); A<int &> a2; printf("%d\n", a2.value); A<const int &> a3; printf("%d\n", a3.value); A<volatile int &> a4; printf("%d\n", a4.value); A<const volatile int &> a5; printf("%d\n", a5.value); A<r_type> a6; printf("%d\n", a6.value); A<cr_type> a7; printf("%d\n", a7.value); return 0; } // output: // 1 // 1 // 1 // 1 // 1 // 1 // 1 The instantiations with a reference type should use the primary class template and not one of the specializations. bye, Christof -- http://cmeerw.org JID: cmeerw jabber.at mailto cmeerw at web.de
Aug 22 2003