我在.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&)的未定义引用”。
发布于 2018-10-04 16:04:58
从构造函数的显式实例化中删除class。
template PolygonPath::PolygonPath<long>(const Polygon<long> &);
和
template Polygon<long> PolygonPath::toPolygon<long>() const;
https://stackoverflow.com/questions/52651035
复制相似问题