c++ - Shared Preferences implementation -
my aim implement class can accessible anywhere, providing key value pairs;
class sharedresources { public: static qmap <qstring,qvariant> *preferences; }; //initialization sharedresources.preferences = new qmap<qstring,qvariant>(); //store data sharedresources.preferences->insert("some_data",some_data); //access data some_data = sharedresources.preferences->value("some_data");
but code not compile.
first error (got similar @ every usage):
/file:line: error: expected unqualified-id before '.' token sharedresources.preferences = new qmap<qstring,qvariant>(); ^
i broke c++ rules, are?
update: using :: error is:
/file:line: error: undefined reference `sharedresources::preferences'
it's better in such case use statically rather dynamically allocated memory (i.e. without new
).
your problem have declare , define static field well. in header file declare it, should defined somewhere in cpp
file like:
// defines variable, default ctor (w/out parameters) qmap<qstring,qvariant> sharedresources::preferences;
of course have link appropriate object file other modules (apart using header file declaration).
Comments
Post a Comment