std::vector 中的 C++ 外部类(定义格式错误)

约瑟夫3d

我在一个外部库中构建了一个类,我希望在其他领域使用它。但是,当我尝试在 std::vector 中使用该类时,出现编译错误

                 from ../../src/geom/geom.cpp:21:
/usr/include/c++/4.8.2/ext/new_allocator.h: In instantiation of `void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = GenUtils::MeshNormalData; _Args = {const GenUtils::MeshNormalData&}; _Tp = GenUtils::MeshNormalData]`:
/usr/include/c++/4.8.2/bits/alloc_traits.h:254:4:   required from `static typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = GenUtils::MeshNormalData; _Args = {const GenUtils::MeshNormalData&}; _Alloc = std::allocator<GenUtils::MeshNormalData>; typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type = void]`
/usr/include/c++/4.8.2/bits/alloc_traits.h:393:57:   required from `static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = GenUtils::MeshNormalData; _Args = {const GenUtils::MeshNormalData&}; _Alloc = std::allocator<GenUtils::MeshNormalData>; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]`
/usr/include/c++/4.8.2/bits/stl_vector.h:906:34:   required from `void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = GenUtils::MeshNormalData; _Alloc = std::allocator<GenUtils::MeshNormalData>; std::vector<_Tp, _Alloc>::value_type = GenUtils::MeshNormalData]’
../../src/geom/geom.cpp:315:47:   required from here
/usr/include/c++/4.8.2/ext/new_allocator.h:120:4: error: use of deleted function `GenUtils::MeshNormalData::MeshNormalData(const GenUtils::MeshNormalData&)`
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^
In file included from ../../src/geom/geom.h:60:0,
                 from ../../src/geom/geom.cpp:21:
../../src/libs/utils/generalUtils.h:94:7: note: `GenUtils::MeshNormalData::MeshNormalData(const GenUtils::MeshNormalData&)` is implicitly deleted because the default definition would be ill-formed:
 class MeshNormalData

在库/generalUtils.h

namespace GenUtils
{
   class MeshNormalData
   {
   public:
      MeshNormalData(){}
   };
}

在 geom.h

#include generalUtils.h

class TestGeo : public Base
{
public:
    TestGeo(){};
private:
    std::vector< GenUtils::MeshNormalData > meshnormals;
    void compute_geo();
};

在geom.cpp中

void TestGeo::compute_geo()
{
    meshnormals.clear()
    GenUtils::MeshNormalData normals()
    //- doing other computation on normals
    meshnormals.push_back( normals );
}

我错过了什么?有什么建议吗?需要帮助破译我的错误。

轨道上的亮度竞赛

错误的关键部分是它说MeshNormalData的复制构造函数的定义被删除。

将产生错误是因为程序的某些内容要求复制构造函数不被删除:可访问和可用。

这里需要副本:

meshnormals.push_back( normals );

因为你不写std::move

如果它是可移动的,您可以在向量中使用不可复制的类但是您可能希望使您的类可复制。大概在你的真实代码中,有一些关于防止这种情况的类型

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

什么是C ++ 17中的std :: vector推导指南?

在C ++中返回std :: vector的有效方法

C ++中的std :: vector与std :: array

g ++ 4.9错误允许std :: vector <C_type_array>

在FreePascal中相当于C ++ std :: vector,std :: deque和std :: map

C ++防止std :: vector中的对象切片

在C ++ std :: vector之外的线程中启动可运行对象

错误C2039:“ vector”:不是“ std”的成员

参加std :: vector C ++

C ++中std :: vector的压缩布尔功能

C ++-vector <>中的std :: unique_ptr为nullptr

如何在C ++ 17中将std :: string转换为std :: vector <std :: byte>?

C ++中std :: vector的内存问题

用户定义的类型和C ++中的std :: vector

C ++中的std :: vector与[]比较慢-为什么?

C ++:错误无法从std :: vector <int> *转换为std :: vector <std :: vector <int>>

在PHP中是否有等效于C ++的std :: vector的代码?

std :: vector析构函数中的分段错误

代码中的C ++ STD错误

Eclipse C ++ std :: vector方法无效的参数错误

C ++-在寻路中对std :: vector进行排序

如何从 C++ 中的模板类访问 std::vector 数据

c++14 中从“const std::vector<cv::Mat>*”到“std::vector<cv::Mat>*”的无效转换

C++ - 构造函数中的 std::vector 初始化

在 MEX C++ 中从 std::vector 创建 MATLAB 数组

c++ 中的 std::vector 默认如何释放

使用 std::views 将 std::vector<string> 转换为 C++20 中的 std::string

在 C++ 中向 std::vector<std::vector<int>> 類添加成員

头文件中的 std::vector<std::vector<float>> 抛出错误 LNK1120