?
=?gb2312?B?wfXquw==?=
Hi folks,
I am running into with such a question when I tried to declare and
define a friend template function in a template class, here is the
code snippet:
#include <iostream>
using namespace std;
template<typename T>
class Test {
friend Test<T> index(Test<T>& start, Test<T>& end, Test<T>& step);
};
template<typename T>
Test<T> index(Test<T>& start, Test<T>& end, Test<T>& step) {
cout << "This is index is working\n";
return Test<T>();
}
int main() {
Test<int> start = Test<int>();
Test<int> end = Test<int>();
Test<int> step = Test<int>();
Test<int> rslt = index(start, end, step);
}
When compiled with VC8.0, a linkage error araised:
Test.obj : error LNK2019: unresolved external symbol "class TVEC<int>
__cdecl index(class TVEC<int> &,class TVEC<int> &,class TVEC<int>
&)" (?index@@YA?AV?$TVEC@H@@AAV1@00@Z) referenced in function _main
I am running into with such a question when I tried to declare and
define a friend template function in a template class, here is the
code snippet:
#include <iostream>
using namespace std;
template<typename T>
class Test {
friend Test<T> index(Test<T>& start, Test<T>& end, Test<T>& step);
};
template<typename T>
Test<T> index(Test<T>& start, Test<T>& end, Test<T>& step) {
cout << "This is index is working\n";
return Test<T>();
}
int main() {
Test<int> start = Test<int>();
Test<int> end = Test<int>();
Test<int> step = Test<int>();
Test<int> rslt = index(start, end, step);
}
When compiled with VC8.0, a linkage error araised:
Test.obj : error LNK2019: unresolved external symbol "class TVEC<int>
__cdecl index(class TVEC<int> &,class TVEC<int> &,class TVEC<int>
&)" (?index@@YA?AV?$TVEC@H@@AAV1@00@Z) referenced in function _main