How to make d-pointer right in Qt -
i've created myclass
class , in order hide members, used d-pointer got error while compiling souce code. here code:
header file:
class myclassprivate; class myclass : public qobject { q_object public: myclass(qobject *parent = 0); ~myclass(); ... signals: public slots: private: myclassprivate *d; };
and related .cpp
myclass::myclass(qobject *parent): qobject(parent), d(new myclassprivate()) { } myclass::~myclass() { delete d; } class myclassprivate { public: myclassprivate(); ...some methods... qtextstream stream; qfile* m_file; }; myclassprivate::myclassprivate(): m_file(new qfile) { }
it says: forward declaration of 'struct myclassprivate'; invalid use of incomplete type 'myclassprivate'
you have put myclassprivate
declaration before using in myclass
constructor. in .cpp
file:
class myclassprivate { // ... }; myclass::myclass(qobject *parent): qobject(parent), d(new myclassprivate()) { }
you might want check out sources on web explaining concept , qt's convenience macros q_d
, q_declare_private
, on:
Comments
Post a Comment