C++ lnk error 2019 unresolved external symbol virtual errors because of an interface...(?)

标签 c++ interface virtual lnk2019

我在制作一个好的界面和使用它时遇到了问题...... 我的设置概览:

“接口(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... 所以 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...”吗?我在网上搜索了很多年,但很难找到很多关于接口(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/

相关文章:

php - 如何在 PHP 中使用接口(interface)和魔术方法

Android 回调不会在应用程序 onStop/OnResume 后再次运行

c# - 可以在虚方法中抛出 NotImplemented 异常吗?

c++ - 对vtable的 undefined reference -C++链接错误

c++ - Qt:长期适应运行应用程序未修改/独立于显示分辨率

c++ - 突然一个 : syntax error: identifier

c++ - clang 标准库错误或 C++ 未定义行为?

c# - 实现后密封接口(interface)

c++ - 为什么 "virtuality"方法在 C++ 中隐式传播?

c++ - 哪种类型的继承更可取?