Can anyone tell what is wrong with this piece of code?
template<class X>
class C {
public:
template<class Y> void f(Y);
};
template<class X, class Y>
void C<X>::f(Y y) {
}
int main() {
C<int> c;
char a = 'a';
c.f(a);
return 0;
}
Compilation:
$ g++ source.cpp
source.cpp:8: error: prototype for ‘void C<X>::f(Y)’ does not match any in class ‘C<X>’
source.cpp:4: error: candidate is: template<class X> template<class Y> void C::f(Y)
Now I can complete the task by declaring and defining the function in line 4, but what would be the consequences of declaring and defining the function at the same time compared to executing it separately? (This is not a discussion about declaring a function in the source header file)
Note: I saw this question , but it seems that the only part that interests me was left separately = (
source
share