explicit specialization -- Error


I'm a beginner in C++ ,here is a part of the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
using namespace std;

struct box
{
	char maker[40];
	float height;
	float length;
	float width;
	float volume;
};
template<typename T>
T compare(T , T);

template<> char* compare(box a ,box b);


As you see, I want to create a function template with another function of explicit specialization. But when I compile these code there are a error
in this line : template<> char* compare(box a ,box b);

And the compiler's error message here:
[Error] template-id 'compare<>' for 'char* compare(box, box)' does not match any template declaration

what wrong with that??
Anyway , I am sorry for my terrible English and thanks in advance.
Declaration 1:
1
2
template<typename T>
T compare(T , T);


You are trying to specialize a template that hasn't been declared.
1
2
template<typename T>
X compare(T , T);


Do you see the difference?
Thanks for reply.
It is really helpful.
Topic archived. No new replies allowed.