【问题标题】:Instantiation of variable but no definition is available [duplicate]变量的实例化但没有定义可用[重复]
【发布时间】:2018-06-21 19:23:16
【问题描述】:

编译该代码时出现链接错误,并且我收到来自 Xcode 的警告:

变量'quickhull::QuickHull::Epsilon'的实例化 此处需要,但没有可用的定义

这里是函数的定义:

namespace quickhull {

    template<>
    const float QuickHull<float>::Epsilon = 0.0001f;

    template<>
    const double QuickHull<double>::Epsilon = 0.0000001;

    /*
     * Implementation of the algorithm
     */

    template<typename T>
    ConvexHull<T> QuickHull<T>::getConvexHull(const std::vector<Vector3<T>>& pointCloud, bool CCW, bool useOriginalIndices, T epsilon) {
        VertexDataSource<T> vertexDataSource(pointCloud);
        return getConvexHull(vertexDataSource,CCW,useOriginalIndices,epsilon);
    }




ConvexHull<FloatType> getConvexHull(const std::vector<Vector3<FloatType>>& pointCloud, bool CCW, bool useOriginalIndices, FloatType eps = Epsilon);




template<typename FloatType>
    class QuickHull {
        using vec3 = Vector3<FloatType>;

        static const FloatType Epsilon;

        ConvexHull<FloatType> getConvexHull(const VertexDataSource<FloatType>& pointCloud, bool CCW, bool useOriginalIndices, FloatType eps);
    public:
        // Computes convex hull for a given point cloud.
        // Params:
        //   pointCloud: a vector of of 3D points
        //   CCW: whether the output mesh triangles should have CCW orientation
        //   useOriginalIndices: should the output mesh use same vertex indices as the original point cloud. If this is false,
        //      then we generate a new vertex buffer which contains only the vertices that are part of the convex hull.
        //   eps: minimum distance to a plane to consider a point being on positive of it (for a point cloud with scale 1)
        ConvexHull<FloatType> getConvexHull(const std::vector<Vector3<FloatType>>& pointCloud, bool CCW, bool useOriginalIndices, FloatType eps = Epsilon);

}

电话

 QuickHull<float> qh; // Could be double as well


  hull = qh.getConvexHull(pointCloud, true, false);

链接错误

  "quickhull::QuickHull<float>::Epsilon", referenced from:
   "quickhull::QuickHull<float>::getConvexHull(std::__1::vector<quickhull::Vector3<float>, std::__1::allocator<quickhull::Vector3<float> > > const&, bool, bool, float)", referenced from:

【问题讨论】:

  • 我们在这里需要一个minimal reproducible example。请阅读:How to Ask.
  • @MichaelWalz 完成
  • template&lt;typename FloatType&gt; 部分仍然不完整。
  • @MichaelWalz 我已经添加了部分头文件,它非常大
  • 请注意minimal reproducible example 中的“最小”。您需要重构代码以仅包含重现错误所需的内容

标签: c++


【解决方案1】:

通常,在类中声明静态数据成员时,您必须在类定义“外部”提供变量定义,例如

class Test {
   public:
   static int g;
};
...
int Test::g = 0;

通过模板“生成”的类也是如此,符号如下:

template<typename FloatType>
class QuickHull {
    static const FloatType Epsilon;
}
...
template<typename FloatType >
QuickHull<FloatType>::Epsilon = 0.0;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多