0

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

  • How are you building your project? What is your IDE? – Andy Prowl Mar 05 '13 at 15:04
  • the more traditional way of doing interfaces, is to have an abstract base class (`GraphicsLibrary`) which has a pure virtual member function (`GraphicsLibrary::drawPoint`), which can then be implemented by the derived class (`OpenGL`) as `OpenGL::drawPoint`. – Sander De Dycker Mar 05 '13 at 15:06
  • @AndyProwl Im using VS2012, compiling it with that... should i rather use the traditional way of making an interface? (as Sander de Dycker says)? – Sebastiaan van Dorst Mar 06 '13 at 11:36

1 Answers1

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);
}
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625