C++错误 C2511:在'Sprite'中找不到重载的成员函数

C++ error C2511: overloaded member function not found in 'Sprite'

本文关键字:重载 找不到 成员 函数 Sprite C2511 错误 C++      更新时间:2023-10-16

我有一个基类叫Renderable2D:

class Renderer;
class Renderable2D
{
protected:
    vec3f m_Position;
    vec2f m_Size;
    unsigned int m_Color;
protected:
    Renderable2D() { }
    Renderable2D(vec3f position, vec2f size)
        : m_Position(position), m_Size(size), m_Color(0xffffffff)
    {
    }
public:
    virtual ~Renderable2D()
    { }
    virtual void Submit(Renderer * renderer) const;
    inline const vec3f& GetPosition() const { return m_Position; }
    inline const vec2f& GetSize() const { return m_Size; }
    inline unsigned int GetColor() const { return m_Color; }
};

我必须在cpp文件中定义的唯一东西是Submit方法,以避免循环包含:

#include "Renderable2D.h"
#include "../renderers/Renderer2D.h"
inline void Renderable2D::Submit(Renderer * renderer) const
{
    renderer->Submit(*this);
}

然后我从Renderable2D派生了一个类,叫做Sprite:

#include "Renderable2D.h"
class Sprite : public Renderable2D
{
protected:
    GLuint m_TextureID;
public:
    Sprite(const vec2f& position, const vec2f& size, const Texture2D * texture);
    void Submit(Renderer * renderer) const override;
    inline const GLuint GetTextureID() const { return m_TextureID; }
};

在cpp文件中,我只定义了构造函数和重写的Submit方法:

#include "Sprite.h"
#include "../renderers/Renderer2D.h"
Sprite::Sprite(const vec2f& position, const vec2f& size, const Texture2D * texture)
    : Renderable2D(vec3f(position.x, position.y, 0), size)
{
    m_TextureID = texture->GetTextureID();
}
inline void Sprite::Submit(Renderer * renderer) const
{  // ERROR HERE
    renderer->Submit(*this);
}

当我尝试编译时,我得到错误C2511,在"Sprite"中找不到重载成员函数。我不明白为什么。签名错了吗?

编辑:这是renderer类它只是所有渲染器的基类

class Renderable2D;
class Rectangle2D;
class Label;
class Sprite;
class Renderer2D
{
protected:
    std::vector<Maths::mat4f> m_TransformationStack;
    const Maths::mat4f * m_TransformationBack;
protected:
    Renderer2D()
    {
        m_TransformationStack.push_back(Maths::mat4f::identity());
        m_TransformationBack = &m_TransformationStack.back();
    }
public:
    inline void Push(const Maths::mat4f& matrix)
    {
        m_TransformationStack.push_back(matrix * m_TransformationStack.back());
        m_TransformationBack = &matrix;
    }
    inline void PushOverride(const Maths::mat4f& matrix)
    {
        m_TransformationStack.push_back(matrix);
        m_TransformationBack = &matrix;
    }
    void Pop()
    {
        if (m_TransformationStack.size() > 1)
            m_TransformationStack.pop_back();
        else
            Logging::Logger::Log(Logging::LogERROR, "Can't pop the first entry of the transformation stack!");
        m_TransformationBack = &m_TransformationStack.back();
    }
    virtual void Begin() {}
    virtual void End() {}
    virtual void Submit(const Renderable2D& renderable) = 0;
    virtual void Submit(const Label& label) = 0;
    virtual void Submit(const Rectangle2D& rect) = 0;
    virtual void Submit(const Sprite& spr) = 0;
    virtual void Flush() = 0;
};

下面是唯一一个扩展了这个类的Renderer的头文件:

#include "Renderer2D.h"
class Batch2DRenderer : public Renderer2D
{
private:
    GLuint m_VAO;
    IndexBuffer * m_IBO;
    GLsizei m_IndexCount;
    GLuint m_VBO;
    VertexData * m_Buffer;
    std::vector<GLuint> m_TextureSlots;
public:
    Batch2DRenderer();
    ~Batch2DRenderer();
    void Begin() override;
    void End() override;
    void Submit(const Renderable2D& renderable) override;
    void Submit(const Label& label) override;
    void Submit(const Rectangle2D& rect) override;
    void Submit(const Sprite& spr) override;
    void Flush() override;
private:
    void init();
    float SubmitTexture(GLuint textureID);
};

实现文件确实很大,但如果需要,我也可以提供。我猜这个错误很容易误导人因为我猜这里还有别的东西

可能是使用内联函数引起的问题。