This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bad_cast


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]