Boost logo

Boost Users :

Subject: Re: [Boost-users] [Exception] How do I inherit custom exception hierarchy from std::runtime_error rather than from std::exception?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2013-11-28 18:23:23


On Thu, Nov 28, 2013 at 3:29 AM, Egor Tensin <egor.tensin_at_[hidden]> wrote:
> Steven,
>
> Could you please specify, you meant the error_info_injector class
> inside the Boost.Exception? I'm just trying to get this straight in my
> head. Or maybe you don't know what class exactly derives from the
> class passed as the parameter?

Allow me -- calling boost::throw_exception throws an internal type
that derives from the type of the passed object. As in the example
below, that internal type's constructor initializes the virtual bases
of the object, but it doesn't know about the virtual bases of the
object -- so they get initialized by their *default* constructor.

#include <iostream>
struct a
{
  int v;
  a(int v): v(v) { }
};
struct b: virtual a
{
  b(): a(1) { }
};
struct c: b
{
  c(): a(2) { }
};
int main()
{
  c x; std::cout << x.v; //prints "2"
  return 0;
}

-- 
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net