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

标签 c++ inheritance overloading

我有一个名为 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”中找不到重载的成员函数。我不明白为什么。签名有错吗?

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

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;
};

这是唯一扩展此类的渲染器的 header :

#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);
};

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

最佳答案

这个问题可能是使用内联函数引起的。阅读此 inline virtual functions它可以帮助你。

关于C++ 错误 C2511 : overloaded member function not found in 'Sprite' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31424570/

相关文章:

C++从已经初始化的父类创建子类

Scala - 隐式类中的重载方法

c++ - 运算符重载逻辑问题

java - 尝试使用 String 和 URL 数组作为参数实现两个构造函数会产生不明确的错误

c++ - std::istream_iterator<> 与 copy_n() 和 friend

c++ - 将具有空值的字符数组写入文件流

Javascript 经典继承调用父级

c++ - Win32 API : How to catch escape key in Edit control?

javascript - 实现浏览器可以使用的媒体设备

python - 让父方法返回子类实例