[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

g++ self reference bug

From: Sebastien Jean
Subject: g++ self reference bug
Date: Thu, 19 Apr 2001 15:49:43 -0700

>From what I can tell, the following seems to be a bug in g++...

ANSI C++ states that it is ok to use the class name within a class
definition as long as the usage does not require the compiler to know the
size of the class.  (ie: self-referential pointers are ok)

This chunk of code work well in other compilers:

class mySingltonClass
    ... stuff ...

    static mySingltonClass* pPointer;

With g++, it causes the compiler to issue this warning:

"ANSI C++ forbids data member 'mySingltonClass' with same name as enclosing

Oddly enough, if you remove the "static", then the error goes away.  Like I
said before, other compilers are just fine with this usage which is
consistent with the official definition.

The following code works around this problem:

class mySingletonClass;                                      // forward
typdef mySingletonClass _mySingletonClass;      // typdef

class mySingltonClass
    ... stuff ...

    static _mySingltonClass* pPointer;              // use of typdef

reply via email to

[Prev in Thread] Current Thread [Next in Thread]