static data member of template class 
Author Message
 static data member of template class

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;

Quote:
}

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



Sun, 15 Dec 2002 03:00:00 GMT  
 static data member of template class
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

Quote:

> 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



Mon, 16 Dec 2002 03:00:00 GMT  
 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



Mon, 16 Dec 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Initialization of static data member of template class

2. Unresolved static template data member exported from DLL

3. template classes with static members

4. template classes with static members

5. Static member definition of template class fails

6. Static member definition of template class fails

7. Static member variables of template class

8. static template class member variable in DLL

9. static members in template class across DLL's

10. template classes with static members

11. Initialising a static data member of a Class?

12. Initialising a static data member of a Class?

 

 
Powered by phpBB® Forum Software