【问题标题】:C++ lnk error 2019 unresolved external symbol virtual errors because of an interface...(?)C++ lnk 错误 2019 由于接口导致的未解决的外部符号虚拟错误...(?)
【发布时间】: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 功能的主... 所以 ma​​in 也有:

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


【解决方案1】:

链接器抱怨DrawingFunctions::drawObstacleUnderConstruction,而你定义了void drawObstacleUnderConstruction,这是一个免费函数。

在定义函数时限定名称。

void DrawingFunctions::drawObstacleUnderConstruction(Obstacle::Type type, const vector<Point>& points)
{
    for( //etcetc )
        ogl.drawPoint(*it, 255, 255, 255, 3.0);
}

【讨论】:

  • 好吧,我已经做到了,但它仍然没有摆脱我的错误:S
猜你喜欢
  • 2013-02-22
  • 2012-05-22
  • 1970-01-01
  • 2018-11-19
  • 1970-01-01
  • 2021-10-30
  • 2019-02-26
  • 2016-06-02
  • 1970-01-01
相关资源
最近更新 更多