template classes with static members 
Author Message
 template classes with static members

Hello!
Does anybody know how to make the template class with static members
and not to cause the LNK2001 "Unresolved external"? Note: I have to
include the header file with my tempate into several *.cpp files.

Best regards, Sergey Surkov

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Thu, 09 May 2002 03:00:00 GMT  
 template classes with static members
template <typename T>
struct AStatic
{
    static T object;

Quote:
};

// still in the header:
template <typename T>
T AStatic<T>::object;    // default initialized
// or: T AStatic<T>::object( 34.5, "help" );    // constructor required
// or: T AStatic<T>::object = 42;    // T convertible from int/non-explict
constructor required

// in source file
class Foo {};
void bar(Foo&);

void foobar()
{
    bar(AStatic<Foo>::object);

Quote:
}

HTH
-- J?rg Barfurth



Quote:
> Hello!
> Does anybody know how to make the template class with static members
> and not to cause the LNK2001 "Unresolved external"? Note: I have to
> include the header file with my tempate into several *.cpp files.

> Best regards, Sergey Surkov



Sat, 11 May 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. template classes with static members

2. template classes with static members

3. static data member of template class

4. Initialization of static data member of template class

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 class with a template member function

11. Template member functions of template classes

12. calling template member function in template class

 

 
Powered by phpBB® Forum Software