我有一个接口,但我不能使用它,因为方法应该是静态的......或另一种解决方案......就我所见不能是静态的...:C++接口错误,非静态成员引用必须是相对于特定对象
有它使用的函数的定义的图形库:是从GraphicsLibrary衍生
GraphicsLibrary.h
virtual void drawText(const std::string& text, const Point& pt, unsigned char r, unsigned char g, unsigned char b);
这里只是要清楚,OpenGL的:
OpenGL.h
class OpenGL : public GraphicsLibrary
OpenGL.cpp从GraphicsLibrary使用虚函数和支架之间是“做”的事情..:
OpenGL.cpp
void GraphicsLibrary::drawText(const std::string& text, const Point &pt, unsigned char r, unsigned char g, unsigned char b)
{
//does things
}
然后是IM我主我使用的方法...但它给出了一个错误
MyMain
OpenGL::drawText(toString(mousePos_world), drawPosition, 255, 0, 0);
错误:非静态成员引用必须是相对于特定对象
我应该如何解决这个问题?我读过,我应该使这个功能是静态的,但我认为我不能......对吗?或者大多数人都这么说,想想为什么用这种方式构建类,以便使用其他类的方法,但那是因为我有一个接口...!