qt - C++ override virtual method throws an error "LNK2001: unresolved external symbol" -


i'm developing c++ qt application. have 1 abstract class , 2 children. 1 of children works way should, second 1 causes error:

freewer.obj:-1: error: lnk2001: unresolved external symbol "public: virtual void __thiscall sierpinski::render(class qpainter &,class qrect)" (?render@sierpinski@@uaexaavqpainter@@vqrect@@@z)

file not found: freewer.obj

the problem is, both of children defined same way.
let's show code.

fractal.h:

#ifndef fractal_h #define fractal_h  #include <qpainter> #include <qrect> #include <qdebug>  class fractal { public:     virtual void render(qpainter &painter, qrect target) = 0; };  #endif // fractal_h 

cantor.h:

#ifndef cantor_h #define cantor_h  #include "fractal.h"  class cantor : public fractal { public:     void render(qpainter &painter, qrect target) q_decl_override; };  #endif // cantor_h 

cantor.cpp:

#include "cantor.h"  void cantor::render(qpainter &painter, qrect target) {     q_unused(painter);     q_unused(target);      qdebug() << "rendering cantor's discontinuum..."; } 

sierpinski.h:

#ifndef sierpinski_h #define sierpinski_h  #include "fractal.h"  class sierpinski : public fractal { public:     void render(qpainter &painter, qrect target) q_decl_override; };  #endif // sierpinski_h 

sierpinski.cpp:

#include "sierpinski.h"  void sierpinski::render(qpainter &painter, qrect target) {     q_unused(painter);     q_unused(target);      qdebug() << "rendering sierpinski triangle..."; } 

now, when want create instance of cantor class, works properly. when want create instance of sierpinski class, causes error wrote above.

when change sierpinsky header file way:

sierpinski.h:

#ifndef sierpinski_h #define sierpinski_h  #include "fractal.h"  class sierpinski : public fractal { public:     void render(qpainter &painter, qrect target)     {         q_unused(painter);         q_unused(target);          qdebug() << "rendering sierpinski triangle...";     } };  #endif // sierpinski_h 

and won't use sierpinski.cpp, works properly. isn't weird? can me please? have mistake? i'd use sierpinski definition same way cantor's.

thank much.

edit:

after question of @joachim isaksson tried add 1 fractal same way cantor , sierpinski , i've got same error sierpinski. new class called koch , it's not working. when leave koch.cpp file out , use definition of render function directly in header file, ok.

first of all, misusing term "children". mean subclasses. children means different in qt world.

the probable reason not have corresponding source files in sources variable in qmake project file.

once make modiication, make sure qmake rerun properly.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -