简体   繁体   English

管理成员函数的模板

[英]Managing Templates on Member Functions

class myclass {
   // Definitions of cotrs and dtor...
   // ...
   // Defining a method of mine that needs a template
   template < typename T >
   void dosome(T& par);
}

What to do in implementation in cpp file? 在cpp文件中执行什么操作? 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 谢谢

您希望标题中包含整个模板定义。

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. 但是,通常您应该在标头中包含模板definitinos。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM