Partial template specialization on a function

Discussion in 'C++' started by mrstephengross, Apr 14, 2005.

  1. I'm trying to specialize one template argument in a member function
    that takes two template arguments. I've seen other posts on this group
    indicating that it's not possible, but I wanted to make sure. Here's
    what the code looks like:

    enum myenum { apple, pear };
    class Foo
    {
    template<myenum E, typename Y> doSomething();
    };

    template<typename Y> Foo::doSomething<apple>() { /* ... */ }

    Which doesn't compile ("explicit template argument list is not
    allowed..."). Any ideas?

    Thanks,
    --Steve
     
    mrstephengross, Apr 14, 2005
    #1
    1. Advertising

  2. mrstephengross wrote:
    > I'm trying to specialize one template argument in a member function
    > that takes two template arguments. I've seen other posts on this group
    > indicating that it's not possible, but I wanted to make sure.


    How many times are you going to ask about something that has been already
    answered, just 'to make sure'? Get yourself a copy of the Standard and
    study clause 14. There are no partial specializations of function
    templates.

    > Here's
    > what the code looks like:
    >
    > enum myenum { apple, pear };
    > class Foo
    > {
    > template<myenum E, typename Y> doSomething();


    If 'doSomething' is meant to be a member function template, you seem to
    be missing the return value type here.

    > };
    >
    > template<typename Y> Foo::doSomething<apple>() { /* ... */ }


    Again, no return value type in sight. And as I already said, no partial
    specialisations of function templates exist in C++.

    > Which doesn't compile ("explicit template argument list is not
    > allowed..."). Any ideas?


    I would recommend overloading. State the problem you're trying to solve
    instead of asking about a non-working "solution".

    V
     
    Victor Bazarov, Apr 14, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexander Stippler

    partial specialization of function template

    Alexander Stippler, Aug 15, 2003, in forum: C++
    Replies:
    1
    Views:
    562
    Rob Williscroft
    Aug 15, 2003
  2. Levent
    Replies:
    5
    Views:
    11,202
    Victor Bazarov
    May 10, 2005
  3. toton
    Replies:
    1
    Views:
    630
  4. vj
    Replies:
    1
    Views:
    505
  5. Hizo
    Replies:
    17
    Views:
    714
    itaj sherman
    Mar 7, 2011
Loading...

Share This Page