" Framework :: Graphics :: Material"的默认构造函数无法引用 - 它是已删除的函数

时间:2017-12-28 12:52:55

标签: c++ visual-studio dll struct constructor

已编辑:已添加Shader类。

我正在编写DLL库,但是MS VS intellisense和编译器抱怨Mesh构造函数。如果我将Mesh构造函数中的Material属性更改为Texture all。我试图将struct更改为class,但它不起作用。删除FFB_FRAMEWORK_API marcro也没有用。

DataStrictures.h

    struct Vertex {
        // position
        glm::vec3 Position;
        // normal
        glm::vec3 Normal;
        // texCoords
        glm::vec2 TexCoords;
        // tangent
        glm::vec3 Tangent;
        // bitangent
        glm::vec3 Bitangent;
    };
    struct Texture
    {
        unsigned int id;
        std::string type;
    };

main.h

#ifdef FFB_FRAMEWORK_EXPORTS
#define FFB_FRAMEWORK_API __declspec(dllexport) 
#else
#define FFB_FRAMEWORK_API __declspec(dllimport) 
#endif

class FFB_FRAMEWORK_API Shader
        {
        public:
            unsigned int ID;
            // constructor generates the shader on the fly
            Shader(const char* vertexPath, const char* fragmentPath, const char* geometryPath = nullptr);

            // activate the shader
            void use();

            // utility uniform functions
            void setBool(const std::string &name, bool value) const;

            void setInt(const std::string &name, int value) const;

            void setFloat(const std::string &name, float value) const;

            void setVec2(const std::string &name, const glm::vec2 &value) const;

            void setVec2(const std::string &name, float x, float y) const;

            void setVec3(const std::string &name, const glm::vec3 &value) const;

            void setVec3(const std::string &name, float x, float y, float z) const;

            void setVec4(const std::string &name, const glm::vec4 &value) const;

            void setVec4(const std::string &name, float x, float y, float z, float w);

            void setMat2(const std::string &name, const glm::mat2 &mat) const;

            void setMat3(const std::string &name, const glm::mat3 &mat) const;

            void setMat4(const std::string &name, const glm::mat4 &mat) const;

        private:
            // utility function for checking shader compilation/linking errors.
            void checkCompileErrors(GLuint shader, std::string type);
        };

struct FFB_FRAMEWORK_API Material
        {
            Shader shader;
            std::vector<Texture> textures;
        };
class FFB_FRAMEWORK_API Mesh
        {
        private:
            std::vector<Vertex> m_vertices;
            std::vector<unsigned int> m_indices;
            Material m_material;
            unsigned int VAO, VBO, EBO;
            void SetupMesh();
        public:
            Mesh(std::vector<Vertex> vertices, std::vector<unsigned int> indices, Material material);
            void Draw(Shader shader);
        };

Mesh.h

Mesh::Mesh(std::vector<Vertex> vertices, std::vector<unsigned int> indices, Material material)
{
    m_vertices = vertices; 
    m_indices = indices;
    m_material = material;
    // now that we have all the required data, set the vertex buffers and its attribute pointers.
    SetupMesh();
}

编译器在m_verticies = vertices之前抱怨

  

严重级代码说明项目文件行抑制状态错误   (主动)E1790的默认构造函数   &#34;框架::显卡::材料&#34;不能被引用 - 它是一个   删除函数FFB_Framework c:\ Users \ User \ Documents \ Visual Studio   2017 \ Projects \ FFB \ FFB_Framework \ Mesh.cpp 7

编辑。 如果我将构造函数更改为

 Mesh::Mesh(std::vector<Vertex> vertices, std::vector<unsigned int> indices, Material material):m_vertices(vertices),m_indices(indices),m_material(material)
{SetupMesh();}

编译器抛出错误:

  

严重级代码描述项目文件行抑制状态   错误LNK2019未解析的外部符号&#34; __ declspec(dllimport)   public:__ cdecl Framework :: Graphics :: Material ::〜Material(void)&#34;   (__imp _ ?? 1Material @ Graphics @ Framework @@ QEAA @ XZ)在函数中引用   &#34; public:__ cdecl Framework :: Graphics :: Mesh :: Mesh(class   std :: vector&gt;,类   std :: vector&gt ;, struct   框架::显卡::材料)&#34;   (?? 0Mesh @图形@框架@@ QEAA @ V'$ @矢量@@ UVertex V'$ @分配器@@@ UVertex性病性病@@@ @@ V'$ @向量IV?$ @分配I @ STD @ @@ 4 @ UMaterial @ 12 @@ Z)FFB_Framework C:\ Users \ Anton \ Documents \ Visual   Studio 2017 \ Projects \ FFB \ FFB_Framework \ Mesh.obj 1

     

严重级代码描述项目文件行抑制状态   错误LNK2019未解析的外部符号&#34; __ declspec(dllimport)   public:__ cdecl Framework :: Graphics :: Material :: Material(struct   Framework :: Graphics :: Material const&amp;)&#34;   (__imp _ ?? 0Material @ Graphics @ Framework @@ QEAA @ AEBU012 @@ Z)在   function&#34; public:__ cdecl Framework :: Graphics :: Mesh :: Mesh(class   std :: vector&gt;,类   std :: vector&gt ;, struct   框架::显卡::材料)&#34;   (?? 0Mesh @图形@框架@@ QEAA @ V'$ @矢量@@ UVertex V'$ @分配器@@@ UVertex性病性病@@@ @@ V'$ @向量IV?$ @分配I @ STD @ @@ 4 @ UMaterial @ 12 @@ Z)FFB_Framework C:\ Users \ Anton \ Documents \ Visual   Studio 2017 \ Projects \ FFB \ FFB_Framework \ Mesh.obj 1

有谁知道错误在哪里?

1 个答案:

答案 0 :(得分:0)

您正在使用m_material变量的作业。在进入Mesh构造函数的主体之前,将调用m_material的默认构造函数,该构造函数将被删除。您可以像这样重新组织构造函数,并为Material

提供匹配的构造函数
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<unsigned int> indices, Material material) : m_vertices(vertices), m_indices(indices), m_material(material)
{
    // now that we have all the required data, set the vertex buffers and its attribute pointers.
    SetupMesh();
}