Initializing static pointer in templated class.

Posted by Anthony on Stack Overflow See other posts from Stack Overflow or by Anthony
Published on 2010-08-04T18:15:21Z Indexed on 2011/02/19 23:25 UTC
Read the original article Hit count: 231

Filed under:
|
|

This is difficult for me to formulate in a Google query (at least one that gives me what I'm looking for) so I've had some trouble finding an answer. I'm sure I'm not the first to ask though. Consider a class like so:

template < class T >
class MyClass
{
  private:
    static T staticObject;
    static T * staticPointerObject;
};
...
template < class T >
T MyClass<T>::staticObject; // <-- works
...
template < class T >
T * MyClass<T>::staticPointerObject = NULL; // <-- cannot find symbol staticPointerObject.

I am having trouble figuring out why I cannot successfully create that pointer object.

Edit:

The above code is all specified in the header, and the issue I mentioned is an error in the link step, so it is not finding the specific symbol.

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates