c++ - How to declare a new class in the header and define it in the source file without this errors? -


i'm on situation want create new class , use in created class (c++), without using different header or source files: both classes shall in same place, 1 way or another. main class shall contain pointer "child" class.

now know in many cases possible define class in header file. in fact, if 1 wants not set pointer "child class", use 1 of methods in header file (e.g., inline methods), 1 have define in source file:

class childclass {     public:         bool myfunctions() { return true; } }  class mainclass {     private:         childclass* pochildclass;         inline bool getresult() { return pochildclass->myfunctions(); } } 

but let's suppose want have pointer there, without call childclass' methods, should able declare childclass , later define in same .cpp file mainclass defined:

//in .hpp class childclass;  class mainclass {     private:         childclass* pochildclass; }  //in .cpp class childclass {     public:         bool myfunctions() { return true; } }  //etc. 

in first moment don't know there of problem. in trying 1 of classes in particular (which based on qwt's qwtplotpicker class), compile errors (in last version):

error: undefined reference `vtable picker' 

the error points out in following code (in .cpp):

class picker : public qwtplotpicker {     q_object public:     picker( qwidget* canvas ) :         qwtplotpicker( canvas ) //here lies error compiler says //... 

so problem? "undefined reference 'vtable'" problem?

thanks help,

momergil

this problem have had forever when using qt. class has q_object macro in must listed in headers before running qmake (as far can tell). may mean putting .cpp file in headers section.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -