473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

static member of template class

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;
}
Jul 19 '05 #1
1 4526
> 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/groups?q=pri...ron.net&rnum=1
Jonathan
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alibek | last post by:
Hello ! I have here template class with static members. and I put definition of the static member in the same ..h file where the class was declared. however, we are getting very stange...
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
18
by: Erik Arner | last post by:
Hi, I really need some help here. After upgrading to g++ 3.4 I have run into all sorts of troubles that I'm sure depends on my lack of proper understanding of C++. I would now like to get it right...
7
by: ank | last post by:
Hi, I was curious about how to define static data member of template class. Should I put the definition in a separate source file or in the same header file as its template class? And when this...
3
by: salem.ganzhorn | last post by:
The following code compiles cleanly, but it looks like gcc 3.4.0 does not emit the static data member into the object file (so I get a link error): #include <iostream> template <class Type>...
1
by: Frederiek | last post by:
Hi, When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. Does that mean that the address of...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
5
by: chgans | last post by:
Hi all, I'm having difficulties with some template static member, especially when this member is a template instance, for example: ---- template<typename T> class BaseT { public: static...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.