Rationale behind restrictions in full template specialization?

N

Nick Bastin

I've done some searching in this newsgroup and on the internet and
haven't found an answer, so I thought I'd ask here... :)

I don't understand why full specialization of a member function
template in a class template is only valid if you fully specialize the
class template as well. Consider the following example:

[header]
template<class T, int ID>
class RSMixin : public T
{
...
template <typename T2>
void setAttribute (std::string name, T2 value);
}

[implementation]
template<class T, int ID>
template<>
void
RSMixin<T, ID>::setAttribute (std::string name, bool value)
{ }

I understand that this isn't valid, but I don't really understand the
rationale behind why.

RSMixin<GenericDriver, 0> foo;
foo.setAttribute ("some attribute", true);

should generate:

void RSMixin<GenericDriver, 0>::setAttribute(std::string, bool);

This seems unambiguous to me, but maybe someone can point out a more
difficult situation where the compiler wouldn't be able to figure it
out?
 
J

Jack Klein

I've done some searching in this newsgroup and on the internet and
haven't found an answer, so I thought I'd ask here... :)

I don't understand why full specialization of a member function
template in a class template is only valid if you fully specialize the
class template as well. Consider the following example:

[header]
template<class T, int ID>
class RSMixin : public T
{
...
template <typename T2>
void setAttribute (std::string name, T2 value);
}

[implementation]
template<class T, int ID>
template<>
void
RSMixin<T, ID>::setAttribute (std::string name, bool value)
{ }

I understand that this isn't valid, but I don't really understand the
rationale behind why.

RSMixin<GenericDriver, 0> foo;
foo.setAttribute ("some attribute", true);

should generate:

void RSMixin<GenericDriver, 0>::setAttribute(std::string, bool);

This seems unambiguous to me, but maybe someone can point out a more
difficult situation where the compiler wouldn't be able to figure it
out?

I would suggest you post this to comp.std.c++, which is a moderated
group. Its purpose is discussion of the (past, present, and future)
C++ language standard and such issues as the rationale for various
decisions made in creating the standard.

This group, and comp.lang.c++.moderated, primarily discuss the usage
of the language as it exists, not why the standard is as it is.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 

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
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top