Thread: Inherited class constructor

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    114

    Inherited class constructor

    I have three classes 1 base and two inherited.. problem is when I try to initialize the it says undefined reference to vtable constructor.Any help? thanks in advance.
    Code:
    #ifndef QUOTE_H_INCLUDED
    #define QUOTE_H_INCLUDED
    #include <string>
    using namespace std;
    class Quote{
    public:
        Quote()=default;
        //Quote(Quote &q):bookNo(q.bookNo),price(q.price) { }
        Quote(const string &book,double sales_price):bookNo(book),price(sales_price){}
        string isbn() const {return bookNo;}
        virtual double net_price(size_t n) const {return n*price;}
        virtual ~Quote()=default;
        static int max;
        virtual void debug();
    private:
        string bookNo;
    protected:
        double price=0.0;
    };
    class Disc_quote:public Quote{
    public:
        Disc_quote() = default;
        Disc_quote(const string &book, double price,size_t qty, double disc ): Quote(book,price), quantity(qty),discount(disc) {}
        double net_price(size_t) const = 0 ;
        //Disc_quote(Disc_quote &d):Quote(d),quantity(d.quantity),discount(d.discount) { }
    protected:
        size_t quantity = 0;
        double discount = 0;
    };
    class Bulk_quote:public Disc_quote{
    public:
        //Bulk_quote(Bulk_quote &b):Disc_quote(b){}
        Bulk_quote(const string&  book,double p,size_t qty,double disc):Disc_quote(book,p,qty,disc) { }
        double net_price(size_t n) const override;
        void debug() override;
        
    };
    class No_disc : public Disc_quote    {
    public:
        No_disc(const string &s,double price,size_t qt,double disc):Disc_quote(s,price,qt,disc) { }
        double net_price(size_t n) const override {
            if(quantity>100)
                return price*quantity;
            else
                return price*quantity*(1-discount);
        
        }
    
    };
    double print_total(ostream &os,const Quote &item,size_t n);
    #endif // QUOTE_H_INCLUDED
    when I try to declare such as
    Bulk_quote("A",1,1,1) it gives error at line 34 that undefined reference to vtable for bulk_quote
    Last edited by Tamim Ad Dari; 06-18-2013 at 01:16 PM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    This error usually means you haven't implemented a virtual destructor.
    Have you implemented virtual ~Quote() ?

    Kurt

    Edit: Sorry it's not the missing destructor that is declared as default
    It's propably any of the other virtual functions you haven't implemented or declared as override and not implemented.
    Last edited by ZuK; 06-18-2013 at 02:22 PM.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    114
    Thanks a Lot.. I totally forgot that I have to define every overriden function..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. im trying to pass an object to an inherited class
    By kdun in forum C++ Programming
    Replies: 3
    Last Post: 05-01-2013, 02:49 AM
  2. how to make an inherited constructor private?
    By thedodgeruk in forum C++ Programming
    Replies: 5
    Last Post: 02-04-2011, 11:05 AM
  3. Cannot declare inherited class of virtual Base
    By rogster001 in forum C++ Programming
    Replies: 6
    Last Post: 12-17-2009, 10:25 AM
  4. Detecting Inherited Class Type
    By leeor_net in forum C++ Programming
    Replies: 9
    Last Post: 03-01-2009, 03:15 PM
  5. Replies: 3
    Last Post: 03-26-2006, 12:59 AM