简体   繁体   English

向量push_back()给出编译器错误C2280

[英]vector push_back() gives the compiler error C2280

I am trying to append a custom class object to a vector of the same type, however when i try to compile my code, the compiler gives the following error 我试图将自定义类对象附加到相同类型的向量中,但是当我尝试编译代码时,编译器给出以下错误

gltf::gltf(const gltf &): attempting to reference a deleted function

my function takes a string (file name) as an argument and loads that file, then parses the file and populates it's variables 我的函数将字符串(文件名)作为参数并加载该文件,然后解析该文件并填充其变量

the function is as follows:- 功能如下:

void enigma::loadModel(std::string file)
{       

    gltf stagingModel;
    stagingModel.loadAsset(file);   // populates my object with data
    model.push_back(stagingModel);  // appends the populated object to a vector array (this line generates the error)

    ....   // the rest of the code
}

my gltf class decleration is as follows:- 我的gltf班级简介如下:

#pragma once
#include <iostream>
#include <vector>
#include <sstream>
#include <fstream>
#include "meshClass.h"
#include "bufferClass.h"
#include <gtx/quaternion.hpp>
#include <gtx/transform.hpp>

#include"stagingNodeClass.h"
#include"stagingMeshClass.h"
#include"stagingAccessorClass.h"
#include"stagingBufferViewClass.h"
#include"stagingImageClass.h"
#include"stagingSamplerClass.h"
#include"stagingTextureClass.h"
#include"stagingMaterialClass.h"
#include"stagingSkinClass.h"

class gltf
{
public:
    gltf();
    ~gltf();

    std::vector<meshClass> mesh;
    std::vector<char> bin;
    glm::mat4 camera;
    glm::mat4 scale;
    void loadAsset(std::string);

private:
    std::vector<stagingNodeClass> stagingNode;
    std::vector<stagingMeshClass> stagingMesh;
    std::vector<stagingAccessorClass> stagingAccessor;
    std::vector<stagingBufferViewClass>  stagingBufferView;
    std::vector<stagingImageClass> stagingImage;
    stagingSamplerClass stagingSampler;
    std::vector<stagingTextureClass> stagingTexture;
    std::vector<stagingMaterialClass> stagingMaterial;
    stagingSkinClass stagingSkins;
    bufferClass stagingBuffer;
    bool isCamera = false;

    bool node(std::string, std::string);
    int getValue(std::string);
    int getCamIndex(std::string);
    glm::mat4 getMatrix(std::string);
    glm::vec3 getVec3();
    glm::vec4 getVec4();
    float getFloatValue(std::string);
    void initScale();

    std::vector<int> getIntArray();
    std::vector<float> getFloatArray();

    std::string getName(std::string);

    std::fstream  asset;
    std::string line;

};

The error you're getting is the consequence of gltf being a non-copyable object, because its copy constructor was implicitly deleted. 您得到的错误是gltf是不可复制对象的结果,因为它的副本构造函数被隐式删除。 Calling push_back on a vector requires that the pushed object either be copyable or movable, and in the latter case, you need to expressly pass an r-value, which you are not doing. 在向量上调用push_back要求被推送的对象是可复制的或可移动的,在后一种情况下,您需要明确传递一个r值,而您并没有这样做。

You haven't explicitly deleted the copy constructor in gltf , so what I have to presume is that one or more of the objects stored in gltf , or possibly one of the objects stored in the (many) vectors inside gltf , is itself non-copyable, which caused your class to implicitly delete its own copy constructor. 您尚未在gltf明确删除副本构造gltf ,因此我必须假定的是,存储在gltf中的一个或多个对象,或者可能存储在gltf中的(许多)向量中的对象之一本身gltf可复制的,这导致您的类隐式删除其自己的副本构造函数。 Do a code audit to find out which object isn't copyable, and either remove it or write your own copy constructor (and probably also move constructor) for this class, or retrofit that object to be properly copyable. 进行代码审核以找出哪个对象不可复制,然后删除该对象或为此类编写自己的复制构造函数(可能还会移动构造函数),或对该对象进行改造以使其可正确复制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用std :: vector.push_back()时出现错误C2280 - Got error C2280 when using std::vector.push_back() 编译器错误C2280,尝试引用已删除的函数operator = - Compiler error C2280, attempting to reference a deleted function operator= 尝试将对象添加到向量时出现错误C2280 - Getting error C2280 when trying to add an object to a vector std :: vector :: push_back一个不可复制的对象给出了编译器错误 - std::vector::push_back a non-copyable object gives compiler error C ++ push_back编译错误“ - C++ push_back compiler error " C++:带有 const int 的 class 的 vector.erase 实例给出“试图引用已删除的函数”错误 C2280 - C++: vector.erase instance of a class with const int gives "attempting to reference a deleted function" error C2280 无法push_back到向量-没有重载错误 - Can't push_back into vector - gives no overload error PlatformToolset和“已删除功能”错误(C2280) - PlatformToolset and “deleted function” error (C2280) C ++为什么当不使用删除的功能时,编译器因错误代码C2280而失败 - C++ Why the compiler failed with the error code C2280 when the deleted function is not used Visual Studio 2013 和 2015 中的 C++ 编译器错误 C2280“试图引用已删除的函数” - C++ Compiler Error C2280 "attempting to reference a deleted function" in Visual Studio 2013 and 2015
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM