static member of template class

T

Tino

From Stroustrup( TC++PL, Appendix C.13 ) I thought that this was the
way (and the only way perhaps) to have a common static member for all
classes generated from a template. Though compiling this with MSVC++
6, it compiles but errors on linking:

unresolved external symbol "protected: static class structure *
store_base::m_pST

I know that MSVC++ 6.0 has shoddy support of template features...does
this case fall in that class. I'd welcome any alternatives or
workarounds.

Regards,
Ryan

class structure{
public:
int i, j;
structure(int i1,int j1) : i(i1), j(j1) {}
};

class store_base{
protected:
static structure* m_pST;
public:
static void set_structure( structure* pST ){ m_pST = pST; }
};

template<class T> class store : public store_base{
private:
T **buffer;
public:
store() : buffer( NULL ) {}
bool Allocate();
T operator()(int i1, int j1) const
{
if( i1 >= 0 && i1 < m_pST->i && j1 >= 0 && j1 < m_pST->j )
return buffer[i1][j1];
}
void set(int i1, int j1, T tVal)
{
if( i1 >= 0 && i1 < m_pST->i && j1 >= 0 && j1 < m_pST->j )
buffer[i1][j1] = tVal;
}
void print();
};

template<class T> bool store<T>::Allocate()
{
buffer = new T*[m_pST->i];
if( buffer == NULL )
{
cout << "unable to allocate" << endl;
return false;
}
for( int n=0; n<m_pST->i; n++ )
{
buffer[n] = new T[m_pST->j];
if( buffer == NULL )
{
cout << "unable to allocate" << endl;
return false;
}
for( int m=0; m<m_pST->j; m++ )
buffer[n][m] = T((m_pST->i+m_pST->j)/2);
}
return true;
}

int main()
{
structure myst(3,4);
store_base::set_structure( &myst );
store<int> storeint;
store<double> storedouble;
storeint.Allocate();
storedouble.Allocate();
return 0;
}
 
J

Jonathan Mcdougall

From Stroustrup( TC++PL, Appendix C.13 ) I thought that this was the
way (and the only way perhaps) to have a common static member for all
classes generated from a template. Though compiling this with MSVC++
6, it compiles but errors on linking:

unresolved external symbol "protected: static class structure *
store_base::m_pST

http://groups.google.ca/[email protected]&rnum=1


Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top