public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Dynamic casting does not appear to be working at all
@ 1998-09-08  2:22 John Allen
  1998-09-09  3:45 ` Martin von Loewis
  0 siblings, 1 reply; 2+ messages in thread
From: John Allen @ 1998-09-08  2:22 UTC (permalink / raw)
  To: egcs-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

A dynamic_cast<> from a base class to a derived class produces
a compile time error.
Also calling a method via a member pointer which is typedef'd as taking
a base class reference to A,
but is in reality expecting a derived class references to B, but is
passed a derived class reference to C,
which is then dynamic_cast<B> works where it should fail.
-- -------------------------------------------------------------------


John Allen

email: john.allen@iona.com



IONA Technologies PLC

Direct dial: +353-1-6372264



The IONA Building

fax: +353-1-6625244



Shelbourne Road

WWW: http://www.iona.com



Dublin 4, Ireland

ftp: ftp.iona.com



Search
the IONA source archives (internal only)
-------------- making software work together (tm) -----------------
 
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Dynamic casting does not appear to be working at all
  1998-09-08  2:22 Dynamic casting does not appear to be working at all John Allen
@ 1998-09-09  3:45 ` Martin von Loewis
  0 siblings, 0 replies; 2+ messages in thread
From: Martin von Loewis @ 1998-09-09  3:45 UTC (permalink / raw)
  To: john.allen; +Cc: egcs-bugs

> A dynamic_cast<> from a base class to a derived class produces a compile
> time error.

Which compiler version? Which source code? On egcs 2.92.02, the
program below compiles fine. Please note that you cannot dynamic_cast
objects, you need to use pointers or similar.

struct A{
  virtual ~A();
};

struct B:A{
};

A::~A(){}

int main()
{
  A *a = new A;
  B *b = dynamic_cast<B*>(a);
}


> Also calling a method via a member pointer which is typedef'd as
> taking a base class reference to A, but is in reality expecting a
> derived class references to B, but is passed a derived class
> reference to C, which is then dynamic_cast<B> works where it should
> fail.

I was not able to translate this description into C++. Can you give an
example as well?

Regards,
Martin


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-09-09  3:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-08  2:22 Dynamic casting does not appear to be working at all John Allen
1998-09-09  3:45 ` Martin von Loewis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).