[英]Explicit template specialization for constructor (g++)
我在.h文件中有這個類定義:
class PolygonPath
{
public:
template<class T> explicit PolygonPath(const Polygon<T> &);
template<class T> Polygon<T> toPolygon() const;
}
在.cpp文件中,我定義了我的方法。 然后,我想為Polygon<float>
和Polygon<long>
定義顯式模板。 所以,我這樣定義它們:
template class PolygonPath::PolygonPath<float>(const Polygon<float> &); //Fail
template class Polygon<float> PolygonPath::toPolygon<float>() const; //Ok
template class PolygonPath::PolygonPath<long>(const Polygon<long> &); //Fail
template class Polygon<long> PolygonPath::toPolygon<long>() const; //Ok
對於構造函數,我無法定義顯式模板專業化。 我在編譯時遇到此錯誤:“ 錯誤:'PolygonPath'不是類模板 ”。 我也嘗試使用以下語法:
template <> PolygonPath::PolygonPath(const Polygon<float> &)
它可以編譯,但是在鏈接上出現另一個錯誤:“對`urchin :: PolygonPath :: PolygonPath(urchin :: Polygon const&)'的未定義引用”。
從構造函數的顯式實例中刪除class
。
template PolygonPath::PolygonPath<long>(const Polygon<long> &);
和
template Polygon<long> PolygonPath::toPolygon<long>() const;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.