[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: g++ self reference bug
From: |
Thomas Roemke |
Subject: |
Re: g++ self reference bug |
Date: |
Fri, 20 Apr 2001 20:20:35 +0200 |
Sebastien,
well, my g++ compiles it. Are you sure, you do not really have
something like
struct mySingltonClass
{
static mySingltonClass* pPointer; // <---- works fine
int mySingltonClass; // <---- causes error
};
int main(int argc, char *argv[])
{
return 0;
}
Thomas
"Sebastien Jean" <address@hidden> schrieb im Newsbeitrag
news:address@hidden
> 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
> class"
>
>
> 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
> declaration
> typdef mySingletonClass _mySingletonClass; // typdef
>
> class mySingltonClass
> {
> ... stuff ...
>
> static _mySingltonClass* pPointer; // use of typdef
> }
>
>
>
>
>