Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

initializing static data member of a nested class

Status
Not open for further replies.

raydona

Programmer
May 12, 2005
27
GB
I have a non-template class, with a static data member, nested inside a class template. I initialized the static data member as shown below, but it produces a compilation error. (I am using Visual.Net.) I wonder if anyone might
offer a solution? I would be very grateful.

template <class X>
class A
{ private:
class B
{ public:
static int item;
.
.
};
};
template <class X>
int A<X>::B::item = 3;

error LNK2001: unresolved external symbol "public: static int A<class
double>::B::item" (?item@B@?$A@Vdouble@@@@2HA)

 
Works fine for me. Is all that code in the header file? It should be because it is still templated.
Code:
template <class X>
class A
{
public:
    class B
    {
    public:
        static int item;
    };
};

template <class X>
int A<X>::B::item = 3;

#include <iostream>

int main()
{
    std::cout << A<double>::B::item << std::endl;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top