![](/img/trans.png)
[英]How do I define a template function within a template class outside of the class definition?
[英]How do I define a constructor outside of a template class?
我有一個類模板,里面有一個尚未定義的構造函數。
我的目標是在類模板之外定義這個構造函數。
這可能嗎? 我怎樣才能做到這一點? 我檢查了我的 C++ 書並在網上搜索,但我似乎找不到答案。 任何幫助,將不勝感激。 謝謝你。
#include <iostream>
template <class T> class Calculate {
public:
Calculate ();
};
int main() {
return 0;
}
// I want to define this constructor right here
template <class T> <int> Calculate () {
std::cout << "Constructor";
}
語法是
template <class T>
Calculate<T>::Calculate()
{
std::cout << "Constructor";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.