Typecasting a Handle object

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Typecasting a Handle object

amar singh
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?
 
eg.,
Handle<Model> modelHW(new HullWhite(rhTermStructure));
modelHW->discount() //<- Does not compile as discount is not a member of a Model
 
 
Thanks,
Amar
 
 
 
 
 


Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
Reply | Threaded
Open this post in threaded view
|

Re: Typecasting a Handle object

Luigi Ballabio-2
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