
static data member of template class
Thanks very much for your response!
I had not defined the static object outside the template body. I did so,
but found the behavior unchanged. Here's what I did:
------------<snip>-----------
template <class AbstractClass, class Key, class Params>
class AbstractBuilder
{
public:
// ~AbstractBuilder (); - not yet implemented - must call builder
destructors
static AbstractClass* newObject (Key);
// static AbstractClass* newObject (Params);
static AbstractClass* newObject (Key, Params);
protected:
AbstractBuilder ();
AbstractBuilder (Key);
// These should be defined as pure virtual, but compiler won't accept
virtual AbstractClass* makeObject ();
virtual AbstractClass* makeObject (Params);
// Get a static instance of the builder catalog
static OMMap <Key, AbstractBuilder <AbstractClass, Key, Params>*>&
getTheBuilderCatalog ();
private:
// ---------- I added this ...
static OMMap <Key, AbstractBuilder <AbstractClass, Key, Params>*>
thebuilderCatalog;
Quote:
};
// Static data members
// ---------- ...and this...
template <class AbstractClass, class Key, class Params>
OMMap <Key, AbstractBuilder <AbstractClass, Key, Params>*>
AbstractBuilder
<AbstractClass, Key, Params> :: thebuilderCatalog;
--------------<snip>--------------
I am -- as you can probably tell -- a c++ newbie. I appreciate your help!
Regards,
Mark
Quote:
> Did you define the static object outside the template body? What you
> have inside the template body is only a declaration; you must define it
> outside the template body, as with any other static class member.
> Danny Kalev
> "The ANSI/ISO C++ Professional Programmer's Handbook"
> http://www.amazon.com/exec/obidos/ASIN/0789720221
> > In the "standalone" initial build of our application, we successfully
> > used the following code:
> > // getTheBuilderCatalog - get a reference to the builder catalog
> > template <class AbstractClass, class Key, class Params>
> > OMMap <Key, AbstractBuilder <AbstractClass, Key, Params>*>&
> > AbstractBuilder
> > <AbstractClass, Key, Params> :: getTheBuilderCatalog ()
> > {
> > static OMMap <Key, AbstractBuilder <AbstractClass, Key, Params>*>
> > theBuilderCatalog;
> > return theBuilderCatalog;
> > }
> > Now, I'm attempting to build this as a library, then link to the (new)
> > application GUI. There are no compile errors (as I'd expect: nothing
> > changed!), but at runtime, theBuilderCatalog is a null reference.
> > Any suggestions as to why the "standalone" version returns a valid
> > reference, but the attempt to incorporate this into a library returns a
> > null reference? I've checked my linker options several times, but find
> > no
> > (obvious) explanation there...
> > Thanks for any suggestions,
> > Mark