Partial Spezialization of member function

R

Rob Williscroft

Paul Schneider wrote in in
comp.lang.c++:
I am getting compiler errors with the following setup

Standard C++ doesn't allow function's (member or not) to be partialy
specialized, you may however add overloads and you may have explicit
specialization's.

If neither of the above is of use to you, implement you function in
a helper class, and partialy specialize the helper:

/* Untested code, expect typo's */

struct X;

template < typename T >
struct helper
{
static void apply( X *that )
{
// default body for X::f< T >() goes here
}
};

struct X
{
template < typename T > void f()
{
helper< T >::apply( this );
}
};

/* Now *partialy* specialize
*/
#include <complex>

template < typename T >
struct helper< std::complex< T > >
{
static void apply( X *that )
{
// body for X::f< std::complex< T > >() goes here
}
};

HTH.

Rob.
 
P

Paul Schneider

Hi,

I am getting compiler errors with the following setup:

template<size_t N, enum one, enum two, enum three>
class Myclass {
double fun();
};

template<size_t N, enum one, enum two, enum three>
double MyClass<N, one, two, three>::fun() { return 0.0;}

The above compiles fine, but as soon as I want to partially specialize
my member function with:

template<size_t N, enum two, enum three>
double MyClass<N, someenum, two, three>::fun() { return 1.0; }

I get:

/home/paultschi/workspace/abcalibration/src/model.cpp:32: error: no
`double abcalibration::Model<N, EDV, forVola, fxVola>::eek:nePerAlpha()'
member function declared in class `abcalibration::Model<N, EDV, forVola,
fxVola>'


/home/paultschi/workspace/abcalibration/src/model.cpp:32: error:
template definition of non-template `double abcalibration::Model<N, EDV,
forVola, fxVola>::eek:nePerAlpha()'

(replace above names with Myclass and fun)

I am grateful for any hints on how to do this.

Cheers,

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top