【发布时间】:2013-02-20 01:00:36
【问题描述】:
我在制作一个好的界面并使用它时遇到了问题...... 我的设置概览:
一个“接口”GraphicsLibrary.H...
virtual void drawPoint(const Point& p, unsigned char r, unsigned char g, unsigned char b, double pointSize);
使用“空”GraphicsLibrary.ccp!因为它是一个接口,所以“OpenGL”是一个图形库......所以我有一个 OpenGL.CPP 与:
void GraphicsLibrary::drawPoint(const Point& p, unsigned char r, unsigned char g, unsigned char b, double pointSize)
{
//some code
}
当然有一个“空”的 OpenGL.h(因为他的头文件是 GraphicsLibrary.h)
然后我有一个具有更具体功能的类,它使用 OpenGL,并使用这些基本绘图功能...(OpenGLVis_Enviroment.cpp):
OpenGL ogl;
void drawObstacleUnderConstruction(Obstacle::Type type, const vector<Point>& points)
{
for( //etcetc )
ogl.drawPoint(*it, 255, 255, 255, 3.0);
}
但我也有一个使用一些 OpenGL 功能的主... 所以 main 也有:
OpenGL openGL;
openGL.drawText(something);
但现在我有很多错误(我对所有其他功能都有相同的错误):
1>OpenGLVis_Environment.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall GraphicsLibrary::drawPoint(struct Point const &,unsigned char,unsigned char,unsigned char,double)" (?drawPoint@GraphicsLibrary@@UAEXABUPoint@@EEEN@Z) referenced in function "void __cdecl DrawingFunctions::drawObstacleUnderConstruction(enum Obstacle::Type,class std::vector<struct Point,class std::allocator<struct Point> > const &)" (?drawObstacleUnderConstruction@DrawingFunctions@@YAXW4Type@Obstacle@@ABV?$vector@UPoint@@V?$allocator@UPoint@@@std@@@std@@@Z)
这是因为我使用“GraphicsLibrary::drawPoint...”吗?我在网上搜索了很长时间,但是很难找到很多关于接口的例子......以及如何使用它们...... 先谢谢各位了
【问题讨论】:
-
你是如何构建你的项目的?你的 IDE 是什么?
-
更传统的接口方式是有一个抽象基类(
GraphicsLibrary),它有一个纯虚成员函数(GraphicsLibrary::drawPoint),然后可以由派生类实现(OpenGL) 为OpenGL::drawPoint。 -
@AndyProwl 我正在使用 VS2012,用它编译它...我应该使用传统的界面制作方式吗? (正如 Sander de Dycker 所说)?
标签: c++ interface virtual lnk2019