Topic: private contructor and static member
Author: olaf@cwi.nl (Olaf Weber)
Date: Fri, 10 Jun 1994 09:18:44 GMT Raw View
Consider the following code.
class C {
C() { }
C(int) { }
public:
static C *pc; // (1a)
static C c1; // (2a)
static C c2; // (3a)
};
C *C::p = new C; // (1b)
C C::c; // (2b)
C C::c(1); // (3b)
Cfront 3.0.1 gives errors for variant 2.
G++ 2.5.8 gives errors for variants 2 and 3.
Reading the ARM r9.4:
The initializer for a static data meber can access anything
that a static member function of the class can.
This implies that (1) and (3) are legal. My gut feeling is that (2)
is legal as well, but am I correct?
Secondly, would it not be a good idea to allow a private destructor to
be implicitly called for static members of a class? In other words,
I want the code above to be legal even if `C::~C()' were private. Any
thoughts on this one?
-- Olaf Weber
Author: jason@cygnus.com (Jason Merrill)
Date: Fri, 10 Jun 1994 19:40:16 GMT Raw View
>>>>> Olaf Weber <olaf@cwi.nl> writes:
> G++ 2.5.8 gives errors for variants 2 and 3.
g++ 2.6.0 will accept all three variants.
> Reading the ARM r9.4:
> The initializer for a static data meber can access anything
> that a static member function of the class can.
> This implies that (1) and (3) are legal. My gut feeling is that (2)
> is legal as well, but am I correct?
I believe that you are.
> Secondly, would it not be a good idea to allow a private destructor to
> be implicitly called for static members of a class? In other words,
> I want the code above to be legal even if `C::~C()' were private. Any
> thoughts on this one?
I think that this is also the intent of the passage you quote.
Jason