partial specialization of function template



 DEVELOP > c-Plus-Plus > partial specialization of function template

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Alexander Stippler"
Date: 15 Aug 2003 04:18:16 AM
Object: partial specialization of function template
Hi,
the following code does not compile. Why and how can I reach the desired
effect?
template <int n, typename T>
double
norm(const T &t)
{ return 0.0; }
template <typename T>
double
norm<2,T>(const T &)
{ return 2.0; }
class A
{
};
int
main()
{
A a;
norm<2>(a);
return 0;
}
regards,
alex
.

User: "Rob Williscroft"

Title: Re: partial specialization of function template 15 Aug 2003 06:25:57 AM
Alexander Stippler wrote in news:3f3ca5a6@news.uni-ulm.de:

Hi,

the following code does not compile. Why and how can I reach the
desired effect?

template <int n, typename T>
double
norm(const T &t)
{ return 0.0; }

template <typename T>
double
norm<2,T>(const T &)
{ return 2.0; }

class A
{
};

int
main()
{
A a;
norm<2>(a);

return 0;
}

#include <iostream>
#include <ostream>
template < int N, typename T>
struct do_norm
{
static double apply( T const &t )
{
return 0.0;
}
};
template < typename T >
struct do_norm< 2, T >
{
static double apply( T const &t )
{
return 2.0;
}
};
template < int N, typename T>
double norm( T const &t )
{
return do_norm< N, T >::apply( t );
}
struct A {};
int main()
{
A a;
std::cout << norm<2>(a) << std::endl;
std::cout << norm<1>(1) << std::endl;
}
HTH
Rob.
--
http://www.victim-prime.dsl.pipex.com/
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER