Managing Templates on Member Functions
class myclass {
// Definitions of cotrs and dtor...
// ...
// Defining a method of mine that needs开发者_如何学C a template
template < typename T >
void dosome(T& par);
}
What to do in implementation in cpp file? I thought ti was good this:
template <typename T>
void myclass::dosome< T >(T& par) {
// My code
}
But compiler gets really mad... What's the syntax in this context? Thankyou
You want the entire template definition in the header.
The syntax is the one used for functions:
template<typename T> void myclass::dosome(T &par) {
// ...
}
However, normally you should include template definitinos in the header.
精彩评论