I have a base class called 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; }
};
The only thing I had to define in the cpp file was the Submit
method to avoid circular inclusion:
#include "Renderable2D.h"
#include "../renderers/Renderer2D.h"
inline void Renderable2D::Submit(Renderer * renderer) const
{
renderer->Submit(*this);
}
Then I derived a class from Renderable2D
called 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; }
};
And in the cpp file I just define the constructor and the overridden Submit
method:
#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);
}
When I try to compile, I get error C2511, overloaded member function not found in 'Sprite'. I don't understand why. Is the signature wrong?
Edit: Here's the renderer class which is just a base class for all the renderers
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;
};
And here's the header of the only Renderer that extends this class:
#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);
};
The implementation file is really big, but I can provide that too if required. I guess the error is very misleading because there's something else here I guess.