using a singleton when you will need more than one instance
hi,
i'd like to use a singleton for one of my classes. The class has an attribute named oid and i will need one instance for every value of oid - i just need to make sure there is no second one.
so i tried:
Code:
class cAnlagenArt {
public:
static cAnlagenArt
* self
( QString oid
);
private:
static QMap<QString, cAnlagenArt* > _self;
}
and tried the following:
Code:
cAnlagenArt
* cAnlagenArt
::self(QString oid
) { if ( ! _self.contains(oid) )
_self[oid] = new cAnlagenArt( oid );
return _self[oid];
}
which gets me lots of
undefined reference to `cAnlagenArt::_self'
how else can i do this?
Re: using a singleton when you will need more than one instance
Have you defined the static member somewhere in the .cpp file?
Code:
QMap<QString, cAnlagenArt* > cAnlagenArt::_self;
Re: using a singleton when you will need more than one instance
noo, i thought i only needed to set pointers to 0 in this way. thank you