jps@cs.brown.edu (John Shewchuk) (08/01/89)
It appears that there is a bug in g++ that deals with static members and
initialization. The following file will not compile in g++ 1.35.1.
Regards,
John Shewchuk
// -*- C++ -*-
///////////////////////////////////////////////////////////////////////////
//
// Example that demonstrates an initialization problem with
// g++ version 1.35.1- (g++ -v).
//
// The line `static X instance_x;' generates:
//
// t.c:20: warning: member `instance_x' cannot be static
// (type `X' needs constructing)
//
// as well as several errors.
//
// According to Dan Weinreb <404@odi.ODI.COM> this works under cfront 2.0.
// Furthermore, he write:
// According to the Product Reference Manual, page 60, sec 9.4:
//
// "Static members obey the usual class member access rules, except that
// they can be initialized (in file scope)."
//
// Also see the C++ Primer.
///////////////////////////////////////////////////////////////////////////
class X {
private:
int x_value;
public:
X(int x) { x_value = x; } // The only constructor- note arg.
};
class Y {
private:
static X instance_x; // Must be initialized.
int y_value;
public:
Y(int y) { y_value = y; }
};
X Y::instance_x(1); // Initialization does not violate access rules.
main()
{
Y(2);
}
John Shewchuk jps@cs.brown.edu