Hi,
i have problem in understanding the logic behind function declaration and definitions which prevents me from writting the function outside the class scope:
so this works
Code:
template <typename Tkey, typename Tvalue>
class CPS_Index {
private:
Tkey key;
Tvalue value;
template<typename T1>
void print(T1 x){
cout << x;
};
public:
CPS_Index(Tkey k=0 ,Tvalue v=0);
};
template <typename Tkey, typename Tvalue>
CPS_Index<Tkey,Tvalue>::CPS_Index(Tkey k ,Tvalue v) : key(k), value(v)
{
print("Constructed!\n");
}
but i would like to write my function print() outside the class. something like :
Code:
template <typename Tkey, typename Tvalue>
class CPS_Index {
private:
Tkey key;
Tvalue value;
template <typename T1>
void print(T1 x);
public:
CPS_Index(Tkey k=0 ,Tvalue v=0);
};
template <typename Tkey, typename Tvalue>
CPS_Index<Tkey,Tvalue>::CPS_Index(Tkey k ,Tvalue v) : key(k), value(v)
{
print("Constructed!\n");
}
template <typename Tkey, typename Tvalue>
void CPS_Index<Tkey,Tvalue>::print( T1 x)
{
cout << x;
}
This of course does not work since T1 is not recognized. How to make it work?
thank you !