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

限于喜欢 提交于 2019-12-13 05:30:24

问题


Im having problems with making a good interface and use it... My setup overview:

An "interface" GraphicsLibrary.H...

virtual void drawPoint(const Point& p, unsigned char r, unsigned char g, unsigned char b, double pointSize);

with an "empty" GraphicsLibrary.ccp! because its an interface, so "OpenGL" is an graphics library... so i have an OpenGL.CPP with:

void GraphicsLibrary::drawPoint(const Point& p, unsigned char r, unsigned char g, unsigned char b, double pointSize)
{
    //some code
}

which has ofcourse an "empty" OpenGL.h (since his header file is the GraphicsLibrary.h)

then i have a class with more specific functions that uses OpenGL, and uses those base drawing functions... (OpenGLVis_Enviroment.cpp):

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

BUT i also have a main that uses some OpenGL functions... so the main has also:

OpenGL openGL;
openGL.drawText(something);

but now i have a lot of those errors (i have the same with all the other functions):

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)

Is this because i use "GraphicsLibrary::drawPoint..." ? I am searching online for ages, but it's hard to find a lot of examples about interfaces.. and how to work with them... Thanks in advance guys


回答1:


The linker complains about DrawingFunctions::drawObstacleUnderConstruction and you defined void drawObstacleUnderConstruction, which is a free function.

Qualify the name when you define the function.

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


来源:https://stackoverflow.com/questions/15226986/c-lnk-error-2019-unresolved-external-symbol-virtual-errors-because-of-an-inter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!