I have a templatized class definition in test.hpp
///////////////////////////////////////////////
class point1 {
public:
int z0;
point1(): z0(1)
{}
};
///////////////////////////////////////////////
class point2 {
public:
int z1;
point2(): z1(2)
{}
};
///////////////////////////////////////////////
template <class T>
class line {
public:
T p1;
void printPoint(void);
};
and in implementation file test.cpp I am trying to specialize the printPoint function of class line
///////////////////////////////////////////////
template<>
void line<point1>::printPoint(void)
{
cout<<p1.z0<<endl;
}
template <class T>
void line<T>::printPoint(void)
{
cout<<p1.z1<<endl;
}
//////////////////////////////////////
and main function is in testmain.cpp
int main()
{
line<point1> r1;
line<point2> r2;
r1.printPoint();
r2.printPoint();
int abc;
cin>>abc;
return 0;
}
But linker throwing error that printPoint function is multiply defined. Is it a correct way of member function specialization of a class if not than how to specialize member function of a templatized class? Please help.