template explicit specialization
hi
one little question about templates
lets say i wrote a templated class
template<class T>
class someclass
{
....
};
and do a specilization for e.g.: integers
template<>
class someclass
{
.....
};
do i have to rewrite the code of each member function or only the functions i want to specialize for this datatype?
thx
that’s not strictly true, you can just specialise a function if you want to in a single class and stil have the catch all function for other things
ie
template<class T>
class someclass
{
void foo(T input);
};
template<class T>
void someclass<T>::foo(T input)
{
}
template<>
void someclass<int>::foo(int input);
//in someclass.cpp
template<>
void someclass<int>::foo(int input)
{
}
ie
template<class T>
class someclass
{
void foo(T input);
};
template<class T>
void someclass<T>::foo(T input)
{
}
template<>
void someclass<int>::foo(int input);
//in someclass.cpp
template<>
void someclass<int>::foo(int input)
{
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement