c++ - How to have structs and pointers of a class as a type so you can pass them to functions? -


i trying write library in qt , contains 3 c++ classes. clsa should single instance per application (that why have instance function). clsa instantiate number of clsb depend on different states should keep pointers interact them later. clsc interface should implement developer later on , instantiated , pointers of them should passed clsa::init function. if developer wants use library he/she should write this:

qlist<clsc*> l; clsc1* 1 = new clsc1(); l.append(one); clsc2* 2 = new clsc2(); l.append(two); //and on  clsa* = clsa::instance(); a->init(l); 

and class clsa looks this:

#include "clsb.h" #include "clsc.h" namespace mrz{ namespace core{  class clsa :public qobject {     q_object  public:        static clsa* instance()                    { if(instance == null) return new clsalertmanager(); }         //stores pointers in qmap        void init(qlist<clsc*> _listofpointers); //line number 37  protected:        static inline  clsc* getclscpointer(qstring _key) //line number 42                    { return clscpointers.value(_key);}  private:        static clsalertmanager* instance;        clsalertmanager(){instance = this;}      // depend on variables method instantiates clsb , store     // pointers in qmap called clsbpointers int id        void initclsb();         qmap<int, clsb*> clsbpointers;       qmap<qstring, clsc*> clscpointers;  };  }  } 

and nothing special class clsb header except have declared struct in this:

 namespace mrz{  namespace core{   struct mystruct { int value; };   class clsb: public qobject {      q_object      //calss definition  };  } } q_declare_metatype(mrz::core::mystruct) 

and in 1 of clsb function:

 bool clsb::somefun(qstring _key)  {    clsc* c = clsa::getclscpointer(_key);    return c->someotherfun(myinstantiatedstruct);  } 

and clsc interface should developed later in application looks like:

 namespace mrz{  namespace core{   class clsc  {   public:     clsc();      bool someotherfun(struct mystruct _struct);//line number 39     { return this->isture(_struct.value);}    protected:     virtual bool istrue(int _value) = 0;     //some virtual function should developed later };  } } 

but when try build project lots of error indicating:

clsc.h:39: error: '_struct' has incomplete type clsc.h:39: error: forward declaration of 'mrz::core::mystruct'  clsa.h:37: error: 'clsc' not declared in scope clsa.h:37: error: template argument 1 invalid  clsa.h:42: error: 'clsc' not name type 

i have included header files fine, , part of "simplified version" of part of code generates errors. , have been searching internet , read may need write wrapper function instanciate pointers before hand me, didn't concept. comment or appreciated.

if want pass struct value (that is, not reference, const reference or pointer it), contents of struct must known code using struct - , of course, when using member variables of struct, exact contents of struct must known. in other words, clsc's code must contain definition of struct mystruct allow compiler generate code fetches value.

in case, may mean struct mystruct needs declared in different headerfile.

you have other errors unrelated, , i'm pretty sure not in code posted, makes decoding them bit difficult.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -