S
salem.ganzhorn
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>
class foo {
public:
foo( Type i )
{
m_i = i;
}
void print() {
std::cout << m_i << std::endl;
}
protected:
static Type m_i;
};
template <> // should this be "template<int>"?
int foo<int>::m_i;
int main( int argc, const char** argv )
{
foo<int> f(3);
f.print();
}
Note that I do not understand the difference between prefixing the
instantiation of the "m_i" data member with "template <>" or "template
<int>". Both compile, neither one includes the storage for
foo<int>::m_i in the compilation unit.
Am I misusing the language? Is this a compiler bug?
TIA!
Salem
not emit the static data member into the object file (so I get a link
error):
#include <iostream>
template <class Type>
class foo {
public:
foo( Type i )
{
m_i = i;
}
void print() {
std::cout << m_i << std::endl;
}
protected:
static Type m_i;
};
template <> // should this be "template<int>"?
int foo<int>::m_i;
int main( int argc, const char** argv )
{
foo<int> f(3);
f.print();
}
Note that I do not understand the difference between prefixing the
instantiation of the "m_i" data member with "template <>" or "template
<int>". Both compile, neither one includes the storage for
foo<int>::m_i in the compilation unit.
Am I misusing the language? Is this a compiler bug?
TIA!
Salem