C++错误 C2511:在'Sprite'中找不到重载的成员函数
C++ error C2511: overloaded member function not found in 'Sprite'
我有一个基类叫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);
};
实现文件确实很大,但如果需要,我也可以提供。我猜这个错误很容易误导人因为我猜这里还有别的东西
可能是使用内联函数引起的问题。
相关文章:
- 为什么 std::sort 找不到合适的(静态成员)函数重载?
- 找不到模板重载
- C++ 模板:重载时找不到基类类型参数方法
- 如何修复找不到匹配的重载函数?
- ADL 找不到重载函数
- 为什么找不到使用命名空间中定义的类型实例化的 std::weak_ptr 的重载运算符==?
- 为什么 std::regex_search 找不到合适的重载?
- C++:创建线程时出现问题;错误 C2672:"std::invoke":找不到匹配的重载函数
- 为什么我们在使用宏时找不到合适的运算符重载
- 当我尝试编译程序时,我遇到了一堆错误,例如:'std::max':找不到匹配的重载函数
- 为什么找不到重载运算符函数?
- 在重载运算符中找不到错误<
- 找不到 VS2010 重载成员函数
- 添加指针导致类错误,找不到重载的成员函数
- 为什么 range-for 找不到 std::istream_iterator 的开始和结束重载?
- G++ 在类型转换后找不到重载函数
- 在"着色器程序"中找不到 C++ 重载成员函数
- 如果存在具有不同参数类型的重载,则在全局命名空间中找不到函数
- 错误C2511-找不到重载的成员函数
- boost.log std::异常格式化程序找不到运算符<< 自己的命名空间中的重载