首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >变量的实例化,但没有可用的定义

变量的实例化,但没有可用的定义
EN

Stack Overflow用户
提问于 2018-01-12 10:35:19
回答 1查看 2.4K关注 0票数 2

在编译该代码时,我会得到链接错误,并且我收到了Xcode的警告:

这里需要实例化变量'quickhull::QuickHull::Epsilon‘,但没有定义

下面是函数的定义:

代码语言:javascript
复制
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);

}

打电话

代码语言:javascript
复制
 QuickHull<float> qh; // Could be double as well


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

连接误差

代码语言:javascript
复制
  "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:
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-12 11:08:42

通常,当在类中声明静态数据成员时,必须在类定义“外部”提供一个变量定义。

代码语言:javascript
复制
class Test {
   public:
   static int g;
};
...
int Test::g = 0;

通过模板“生成”的类也是如此,其表示法如下:

代码语言:javascript
复制
template<typename FloatType>
class QuickHull {
    static const FloatType Epsilon;
}
...
template<typename FloatType >
QuickHull<FloatType>::Epsilon = 0.0;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48224429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档