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

'function' : cannot be explicitly specialized error

P: n/a
Say I have a class template as follows

template<typename T>
class foo
{
public:
void test();
};

template<typename T>
void foo<T>::test()
{
// function implementation
}

Now if i want to specialize it for say strings, I would do it as
follows
template<>
class foo<string>
{
public:
void test();
};

template<//Gives a error "function cannot be specialized"
void foo<string>::test()
{
// function implementation
}

My question is why do I need to omit the "template<" for functions
of specialized template class? I am trying this with Visual C++
Express 2005 edition.

Jul 11 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Aarti wrote:
Say I have a class template as follows

template<typename T>
class foo
{
public:
void test();
};

template<typename T>
void foo<T>::test()
{
// function implementation
}

Now if i want to specialize it for say strings, I would do it as
follows
template<>
class foo<string>
{
public:
void test();
};

template<//Gives a error "function cannot be specialized"
void foo<string>::test()
{
// function implementation
}

My question is why do I need to omit the "template<" for functions
of specialized template class? I am trying this with Visual C++
Express 2005 edition.
Because the standard says so. Note that foo<string>::test (assuming string
is a type) is not a template. It is an ordinary member function of the
specialised template foo.

--
rbh
Jul 11 '07 #2

P: n/a
On Jul 11, 4:47 am, Robert Bauck Hamar <roberth+n...@ifi.uio.no>
wrote:
Aarti wrote:
Say I have a class template as follows
template<typename T>
class foo
{
public:
void test();
};
template<typename T>
void foo<T>::test()
{
// function implementation
}
Now if i want to specialize it for say strings, I would do it as
follows
template<>
class foo<string>
{
public:
void test();
};
template<//Gives a error "function cannot be specialized"
void foo<string>::test()
{
// function implementation
}
My question is why do I need to omit the "template<" for functions
of specialized template class? I am trying this with Visual C++
Express 2005 edition.

Because the standard says so. Note that foo<string>::test (assuming string
is a type) is not a template. It is an ordinary member function of the
specialised template foo.

--
rbh- Hide quoted text -

- Show quoted text -
Ok Got it. Thanks!!!

Jul 12 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.