C++ Bug compiling the 'virtual' keyword

Adam Pierce adam@indigointeractive.com.au
Mon Jun 5 23:43:00 GMT 2000


Thanks for the excellent compiler. I use gcc frequently on Linux and find
it very useful.
I've just installed gcc-2.95.2 on my Sparc/Solaris 7 box and have noticed
an odd problem. Consider this very simple header file..
class MyClass
{
        MyClass  *_pNext;
public:
        MyClass();
        virtual ~MyClass();
        virtual MyClass *GetNext() 
const { return _pNext; }
};
If I put this in /usr/local/include, my source files (located elsewhere)
can include it and it compiles perfectly. However, if I move the header
file to /usr/include, or any subdirectory under /usr/include, I get this:
gcc -o MyClassTest MyClassTest.cc
In file included from MyClassTest2.cc:3:
/usr/include/MyClass.h:9: `MyClass' declared as a `virtual' field
/usr/include/MyClass.h:9: declaration of `int MyClass::MyClass'
/usr/include/MyClass.h:7: conflicts with previous declaration `void
MyClass::MyClass(int)'
/usr/include/MyClass.h:9: parse error before `*'
MyClassTest.cc is only one line:
#include <MyClass.h>
I can stop these errors by removing all ocurrences of the word 'virtual'
and defining a typedef for all my pointers - here's the changed header
file which compiles OK:
class MyClass;
typedef MyClass *PMyClass;
class MyClass
{
        PMyClass  _pNext;
public:
        MyClass();
        ~MyClass();
        PMyClass GetNext() 
const { return _pNext; }
};
This is not really an acceptable workaround because I can no longer
use 'virtual'.
Sorry if this description was a bit long-winded but I haven't been able
to isolate the problem any more than this. This is really causing havoc
with my current project. Please let me know if there is some way I can
fix this.
Thanks. Seeya.
--
Adam Pierce
Indigo Interactive
Lv 2, 71 Balfour St
Chippendale NSW
Australia 2008
  Ph +61-2-9698-6222
 Fax +61-2-9698-6333
 



More information about the Gcc-bugs mailing list