On Wed, 2010-09-29 at 09:34 +0200, simone pilozzi wrote:
> I am working on a pricer for a set of bonds with different features.
> I would like to start with a shared_ptr to the generic class bond,
> then specify the type (floaters, fixed, callable ...whatever) once it
> is known.
> Ideally the code should look like this
>
> shared_ptr<Bond> GenericBond( new bond(..constructor for bond))
>
> if( strcmp(bondtype.c_cstr(),"FRN")==0) {
> GenericBond "is now" shared_ptr<floatingratebond>
> }
>
> Is that possible?
Not exactly as above, but you can just leave the pointer empty at the
beginning and instantiate the correct class later:
shared_ptr<Bond> GenericBond;
if( strcmp(bondtype.c_cstr(),"FRN")==0) {
GenericBond.reset(new FloatingRateBond(...));
}
Luigi
--
Weiler's Law:
Nothing is impossible for the man who doesn't have to
do it himself.
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users