bad_cast.cpp

来自「最新的版本ACE-5.6.8,刚从外文网上搬下,与大家分享.」· C++ 代码 · 共 55 行

CPP
55
字号
// file      : Example/ExH/BadCast/bad_cast.cpp
// author    : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2002-2003 Boris Kolpackov
// license   : http://kolpackov.net/license.html

/* FUZZ: disable check_for_improper_main_declaration */

#include "Utility/ExH/System/Exception.hpp"

#include <iostream>

using std::cerr;
using std::endl;


struct A
{
  virtual
  ~A() {}
};

struct B
{
  void
  foo () {}
};

void
foo ()
{
  A a;

  A& ar (a);

  B& br (dynamic_cast<B&> (ar));

  br.foo ();
}

int
main ()
{
  try
  {
    foo ();
  }
  catch (Utility::ExH::System::Exception const& ex)
  {
    cerr << "Caught Utility::ExH::System::Exception: "
         << ex.what ()
         << endl;
  }
}
//$Id: bad_cast.cpp 80826 2008-03-04 14:51:23Z wotte $

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?