我在制作一个好的界面和使用它时遇到了问题...... 我的设置概览:
“接口(interface)”GraphicsLibrary.H...
virtual void drawPoint(const Point& p, unsigned char r, unsigned char g, unsigned char b, double pointSize);
带有“空”GraphicsLibrary.ccp!因为它是一个接口(interface),所以“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... 所以 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...”吗?我在网上搜索了很多年,但很难找到很多关于接口(interface)的例子……以及如何使用它们…… 提前谢谢大家
最佳答案
链接器提示 DrawingFunctions::drawObstacleUnderConstruction
而您定义了 void drawObstacleUnderConstruction
,这是一个自由函数。
定义函数时限定名称。
void DrawingFunctions::drawObstacleUnderConstruction(Obstacle::Type type, const vector<Point>& points)
{
for( //etcetc )
ogl.drawPoint(*it, 255, 255, 255, 3.0);
}
关于C++ lnk error 2019 unresolved external symbol virtual errors because of an interface...(?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15226986/