Article View: gnu.g++.bug
Article #1185Problem with nested classes
From: Robert Mollitor
Date: Tue, 29 Dec 1992 18:29
Date: Tue, 29 Dec 1992 18:29
230 lines
4323 bytes
4323 bytes
I have encountered a problem with the g++ compiler. I have included
three versions (A, B, and C) of the same test program. I would
prefer to use version A, but would settle for version B. However, only
version C works the way I want it to.
Is my approach confused or are there compiler bugs lurking about (other
than the self-proclaimed one)?
Thanks,
Robert Mollitor (robert@visix.com)
-----------
gcc version 2.3.2
SunOS 4.1
g++ -o xxx xxx.c
A (during compile):
> xxx.c:39: Internal compiler error.
> xxx.c:39: Please report this to `bug-g++@prep.ai.mit.edu'.
B (during run):
> foo5
> foo5
C (during run):
> foo5
> foo3 bar9
/* A **********************************************************/
extern "C"
{
#include <stdio.h>
void printf(const char *, ...);
}
class object
{
public:
object() { foo = 5; }
virtual void Print() { printf("foo%d\n", foo); }
class Manager
{
public:
virtual object *CreateObject() { return new object; }
};
int foo;
};
class subobject : public object
{
public:
subobject() { foo = 3; bar = 9; }
void Print() { printf("foo%d bar%d\n", foo, bar); }
class Manager : object::Manager
{
public:
object *CreateObject() { return new subobject; }
};
int bar;
};
main(int argc, char **argv)
{
object::Manager objectManager;
subobject::Manager subobjectManager;
object *object1, *object2;
object1 = objectManager.CreateObject();
object2 = subobjectManager.CreateObject();
object1->Print();
object2->Print();
}
/***********************************************************/
/* B **********************************************************/
extern "C"
{
#include <stdio.h>
void printf(const char *, ...);
}
class object
{
public:
object() { foo = 5; }
virtual void Print() { printf("foo%d\n", foo); }
class Manager
{
public:
virtual object *CreateObject() { return new object; }
};
int foo;
};
class subobject : public object
{
public:
subobject() { foo = 3; bar = 9; }
void Print() { printf("foo%d bar%d\n", foo, bar); }
class xManager : object::Manager /*** changed ***/
{
public:
object *CreateObject() { return new subobject; }
};
typedef xManager Manager; /*** added ***/
int bar;
};
main(int argc, char **argv)
{
object::Manager objectManager;
subobject::Manager subobjectManager;
object *object1, *object2;
object1 = objectManager.CreateObject();
object2 = subobjectManager.CreateObject();
object1->Print();
object2->Print();
}
/***********************************************************/
/* C **********************************************************/
extern "C"
{
#include <stdio.h>
void printf(const char *, ...);
}
class object
{
public:
object() { foo = 5; }
virtual void Print() { printf("foo%d\n", foo); }
class Manager
{
public:
virtual object *CreateObject() { return new object; }
};
int foo;
};
class subobject : public object
{
public:
subobject() { foo = 3; bar = 9; }
void Print() { printf("foo%d bar%d\n", foo, bar); }
class xManager : object::Manager
{
public:
object *CreateObject() { return new subobject; }
};
typedef xManager Manager;
int bar;
};
main(int argc, char **argv)
{
object::Manager objectManager;
subobject::xManager subobjectManager; /*** changed ***/
object *object1, *object2;
object1 = objectManager.CreateObject();
object2 = subobjectManager.CreateObject();
object1->Print();
object2->Print();
}
/***********************************************************/
--
Robert Mollitor robert@visix.com
Visix Software Inc. ...!uupsi!visix!robert
Technical Details
Message-ID:
<9212291829.AA00556@corrado.visix.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!porsche.visix.com!robertShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!porsche.visix.com!robert From: robert@porsche.visix.com (Robert Mollitor) Subject: Problem with nested classes Message-ID: <9212291829.AA00556@corrado.visix.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Tue, 29 Dec 1992 18:29:30 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 231