Partial Spezialization of member function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Schneider

    #1

    Partial Spezialization of member function

    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>::onePer Alpha()'
    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>::onePer Alpha()'

    (replace above names with Myclass and fun)

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

    Cheers,

    Paul
  • Rob Williscroft

    #2
    Re: Partial Spezialization of member function

    Paul Schneider wrote in news:cjh1j6$cni $1@trane.wu-wien.ac.at in
    comp.lang.c++:
    [color=blue]
    > I am getting compiler errors with the following setup[/color]

    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.
    --

    Comment

    Working...