开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜