Login  Register

Re: allocating an object of abstract class type error

Posted by Luigi Ballabio on Jan 12, 2017; 11:32am
URL: http://quantlib.414.s1.nabble.com/allocating-an-object-of-abstract-class-type-error-tp17968p17971.html

No, I don't think there is.


On Thu, Jan 12, 2017 at 2:02 PM Jerry Jin <[hidden email]> wrote:
Hi Luigi

Thanks, is there any tool or document to identify which class is abstract that I can use new to allocate memory?

I'm working a wrapper program, which iterate all classes, hence it would be great to know which classes I can't do 'new' before compiling

Regards
Jerry

On Thu, Jan 12, 2017 at 7:33 PM, Luigi Ballabio <[hidden email]> wrote:
A class is abstract when it (or one of its base classes) declares a pure virtual method and doesn't define it.
In your case: CmsSpreadCouponPricer inherits from FloatingRateCouponPricer, which declares a bunch of virtual methods:

        virtual Real swapletPrice() const = 0;
        virtual Rate swapletRate() const = 0;
        virtual Real capletPrice(Rate effectiveCap) const = 0;
        virtual Rate capletRate(Rate effectiveCap) const = 0;
        virtual Real floorletPrice(Rate effectiveFloor) const = 0;
        virtual Rate floorletRate(Rate effectiveFloor) const = 0;
        virtual void initialize(const FloatingRateCoupon& coupon) = 0;

so FloatingRateCouponPricer is abstract. CmsSpreadCouponPricer doesn't define them, so it's also abstract. LognormalCmsSpreadPricer inherits from CmsSpreadCouponPricer and defines them (that is, gives them actual bodies) so it's a concrete class and can be instantiated.
For more details, you can probably check any C++ book.

Cheers,
    Luigi


On Thu, Jan 12, 2017 at 4:52 AM Jerry Jin <[hidden email]> wrote:
Hello, QuantLib community

I'm getting error 'allocating an object of abstract class type error' sometimes while working with some classes

For example:

return new CmsSpreadCouponPricer(correlation);

How do I know which class is abstract and can't allocate memory?

Thanks!

Regards
Jerry
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users