我有一个名为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
的{{1}}派生了一个类:
Sprite
在cpp文件中我只定义了构造函数和重写的#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; }
};
方法:
Submit
当我尝试编译时,我收到错误C2511,在&Spag'中找不到重载的成员函数。我不明白为什么。签名错了吗?
编辑:这里是渲染器类,它只是所有渲染器的基类
#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);
}
这里是唯一一个扩展此类的渲染器的标题:
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;
};
实现文件非常大,但如果需要,我也可以提供。我猜这个错误是非常误导的,因为我猜这里有别的东西。