Partial template specialization on a function

M

mrstephengross

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
 
V

Victor Bazarov

mrstephengross said:
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
 

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,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top