Afficher un message
Vieux 07/02/2008, 17h55   #2
pastbin@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: specialization of member template

On Feb 7, 5:34 pm, mark....@gmail.com wrote:
> Hello,
>
> I couldn't figure out how to specialize the following member template:
>
> #include <iostream>
> template <typename T1> class sample {
> T1 value;
>
> public:
> sample(T1 v) : value(v) {}
> template <typename T2> T1 val(T2 arg);
>
> };
>
> template <typename T1> template <typename T2> T1 sample<T1>::val(T2 arg)
> {
> return arg + value;
>
> }
>
> template <typename T1> template <> T1 sample<T1>::val(char arg)
> {
> return arg + value;
>
> }
>
> int main()
> {
> sample<int> s(0);
> char c = 'a';
> int i = 10;
> std ::cout << s.val(c) << std::endl;
> std::cout << s.val(i) << std::endl;
> return 0;
>
> }
>
> I only want to partial specialize with T2 = char. Above gives error
> "enclosing class templates are not explicitly specialized"
>
> How do I fix this? Thanks.
>
> Mark


You can't explicitly specialize a class or member template unless its
enclosing class templates are also explicitly specialized.
  Réponse avec citation
 
Page generated in 0,06052 seconds with 9 queries