bad_cast
Thomas Kunert
kunert@physik.tu-dresden.de
Tue Jul 28 07:45:00 GMT 1998
Nyny wrote:
>
> Hi,
>
> I can not find the bad_cast exception in any header.
> I'm using snapshot 19980707.
> According to the dec96 draft of the standard, still cannot
> get a newer one ~:-(
> in clause 5.2.7
> 9 The value of a failed cast to pointer type is the null pointer value
> of the required result type. A failed cast to reference type throws
> bad_cast (18.5.2).
Hi Nyny,
Don't worry about the position of the header files, just try if the
*compiler* finds them. Have you ever asked it about that? Try the
following program.
#include <iostream>
#include <typeinfo>
class A {
public:
virtual ~A(){}
};
class B : public A {};
int main()
{
A a;
try {
dynamic_cast<B&>(a);
} catch (bad_cast) {
cout << "successfully caught!" << endl;
}
}
That proves the presence of class bad_cast.
Just for the curious:
The header <typeinfo> is to be found in .../lib/gcc-lib/.../include .
--
Thomas Kunert
More information about the Gcc
mailing list