N
nishit.gupta
I was having a problem with template class memer function definition ,
so i serched the net
and find that template class member fuction definition should be in
header file else compilation
will be successful but not linking.
Can somebody help me in telling the exact reason why compiler cannot
find the reference of
template class member function definition defined in cpp file??
following problem is not linking (undefined reference of func)but
getting copiled
*************************
#test.h
#include<iostream>
using namespace std;
template<class TYPE> class A {
public:
TYPE func();
};
******************************
#test.cpp#include<iostream>
#include "temp.h"
using namespace std;
template <class TYPE>
TYPE A<TYPE>::func()
{
cout<<"Hello\n";
}
*********************************
#main.cpp
#include"temp.h"
int main(){
A<int> obj;
obj.func();
}
**************************
so i serched the net
and find that template class member fuction definition should be in
header file else compilation
will be successful but not linking.
Can somebody help me in telling the exact reason why compiler cannot
find the reference of
template class member function definition defined in cpp file??
following problem is not linking (undefined reference of func)but
getting copiled
*************************
#test.h
#include<iostream>
using namespace std;
template<class TYPE> class A {
public:
TYPE func();
};
******************************
#test.cpp#include<iostream>
#include "temp.h"
using namespace std;
template <class TYPE>
TYPE A<TYPE>::func()
{
cout<<"Hello\n";
}
*********************************
#main.cpp
#include"temp.h"
int main(){
A<int> obj;
obj.func();
}
**************************