?
=?iso-8859-1?q?Erik_Wikstr=F6m?=
The following code works:
#include <iostream>
template<class T>
struct Test
{
T t;
template<class T, template<class U = T> class V>
Test<T>& foo(V<T>& f)
{
f.t = 5;
return *this;
}
};
int main() {
Test<int> t;
t.foo(t);
std::cout << t.t;
}
However, if I try to move the definition of the foo()-function outside
of the declaration like so:
template<typename T, template<typename U = T> class V>
Test<T>& Test<T>::foo(V<T>& f)
{
f.t = 5;
return *this;
}
It does not compile (VC++8.0) with the following error-message:
test.cpp(24) : error C2244: 'Test<T>::foo' : unable to match function
definition to an existing declaration
definition
'Test<T> &Test<T>::foo(V<T> &)'
existing declarations
'Test<T> &Test<T>::foo(V<T> &)'
Anyone have an idea of how to make this work?
#include <iostream>
template<class T>
struct Test
{
T t;
template<class T, template<class U = T> class V>
Test<T>& foo(V<T>& f)
{
f.t = 5;
return *this;
}
};
int main() {
Test<int> t;
t.foo(t);
std::cout << t.t;
}
However, if I try to move the definition of the foo()-function outside
of the declaration like so:
template<typename T, template<typename U = T> class V>
Test<T>& Test<T>::foo(V<T>& f)
{
f.t = 5;
return *this;
}
It does not compile (VC++8.0) with the following error-message:
test.cpp(24) : error C2244: 'Test<T>::foo' : unable to match function
definition to an existing declaration
definition
'Test<T> &Test<T>::foo(V<T> &)'
existing declarations
'Test<T> &Test<T>::foo(V<T> &)'
Anyone have an idea of how to make this work?