Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wish to define a specialization of a templated class's templated method outside of the class declaration as shown below However the indicated error message is generated No error occurs if the class is not templated Thank You Kindly

C++
template<typename T>
struct cfoo
{
	template<typename U>
	void bar(U);
};
template<typename T>
template<>
void cfoo<T>::bar<int>(int) {} // error C2768 : 'cfoo<T>::bar' : illegal use of explicit template arguments


What I have tried:

Attempted various varieties of syntax which I do not wish to duplicate again here
Posted
Updated 15-Dec-21 10:51am

1 solution

You can't specialize the function template without also specializing the class template to which it belongs. See here[^].
 
Share this answer
 
Comments
CPallini 15-Dec-21 17:18pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900