Topic: Static member not inizialized...
Author: "Daniele Pallastrelli" <dapallas@tin.it>
Date: 2000/11/20 Raw View
Hi all,
this code, compiled with gcc, don't work:
***********************
#include <iostream>
class RegEntry {
public:
RegEntry( int i ) : dato(i) { cout << "RegEntry::RegEntry( int )" <<
endl; }
RegEntry() : dato(1) { cout << "RegEntry::RegEntry()" << endl; }
void print() const { cout << dato << endl; }
private:
int dato;
};
template <typename T>
class C1 {
public:
static void publish() { r.print(); }
protected:
C1() { const RegEntry& dummy = r ; }
private:
static const RegEntry r;
};
template <typename T>
const RegEntry C1<T>::r( 2 );
class Pluto : public C1<Pluto>
{
public :
Pluto() { cout << "Pluto()" << endl; }
};
int main()
{
C1<int>::publish();
return 0;
}
***********************
Obviusly, the result shuld be 2. Instead, I always obtain 0, like the
constructor used for C1::r were a default constructor created by the
compiler!
Thanks,
Daniele.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]