Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Downcasting in NIH

3 views
Skip to first unread message

Richard M Emberson Jr

unread,
Sep 20, 1990, 11:10:23 AM9/20/90
to

I am trying to compile the latest NIH class libary with g++ version 1.37.2 beta.

The problem comes down to the following:

class A {
int i;
};

class B : public A {
char *p;
public:
static B& castdown(A& p) { return (B&)p; } // error
static B* castdown(A* p) { return (B*)p; }
};

G++ lets me cast a pointer but I get the following message if I try to
downcast a reference:

t.c: In function class B &static B::castdown (class A &):
t.c:8: type `B' is not a base type for type `A'

The NIH class library uses such downcasts. How can I get g++ to accept
a downcast of a reference??


Richard Emberson
r...@spl26.spl.fac.com

0 new messages