By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,940 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,940 IT Pros & Developers. It's quick & easy.

Partial template specialization on a function

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.