[Qt-interest] Small problem with QMap

Juan D Guzman lostinthecode at googlemail.com
Wed Mar 11 16:48:03 CET 2009


Benjamin Sonnemann wrote:
> You have to instantiate the static member somewhere.
> Most probably you wnat this in your cpp file:
>
> QMap<QString, MainMenuI *> Sample::items;
>
> just put it on the top if you want the default constructor.
>
> Benjamin Sonnemann
>
>
> On Wed, Mar 11, 2009 at 4:11 PM, Juan D Guzman 
> <lostinthecode at googlemail.com <mailto:lostinthecode at googlemail.com>> 
> wrote:
>
>     Ok so I am still trying to learn the ropes in C++ coming from a C#
>     background.  I have the following code
>
>     class Sample
>
>     {
>
>     public:
>
>        Sample()
>
>        {
>
>        }
>
>        ~Sample()
>
>        {
>
>        }
>
>        static void addItem(QString key, MainMenuI *iMenu);
>
>     private:
>
>        static QMap<QString, MainMenuI *> items;
>
>     };
>
>
>     and in my cpp file i have the following
>
>
>     void Sample::addItem(QString key, MainMenuI *iMenu)
>     {
>        items.insert(key, iMenu);
>
>     }
>
>
>     when i try to compile though i get the following error:
>
>
>     sample.obj:-1: error:  unresolved external symbol "private: static
>     class
>     QMap<class QString,class MainMenuI *> Sample::items"
>     (?items at Sample@@0V?$QMap at VQString@@PAVMainMenuI@@@@A)
>
>
>     any ideas?
>
>     _______________________________________________
>     Qt-interest mailing list
>     Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>     http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
thanks i knew it was something beyond simple.  just the idiosyncrasies 
of C++.



More information about the Qt-interest-old mailing list