Re: Typecasting a Handle object

Posted by Luigi Ballabio-2 on
URL: http://quantlib.414.s1.nabble.com/Typecasting-a-Handle-object-tp2689p2690.html

At 09:15 AM 9/25/03, amar singh wrote:
>I have a handle to an object , which actually points to derived class .My
>question is, what is the ideal way to be able to call a method of the the
>derived class, if it is not a function in the base class?

Hi,

class Foo {
   public:
     virtual ~Foo() {};
};

class Bar {
   public:
     void baz();
};

Handle<Foo> h(new Bar);

h->baz(); // this doesn't compile;

Handle<Bar> h2 = h;   // under the hood, this is a dynamic_cast
h2->baz();            // this works

Bye,
         Luigi