1
votes

I'm getting this error when i make an object of a child class which implements virtual function of Base class.

error LNK2001: unresolved external symbol "public: virtual void __thiscall CateringOrder::[Order]::calcTotals(void)" (?calcTotals@?QOrder@@CateringOrder@@UAEXXZ)

whereas my code is

class Order
{
private:
    float SANDWICH_PRICE;
    float TOCOS_PRICE;

public:
    string customerType;
    int NumberOfSandwiches;
    int NumberOfTacos;
    float SandwichSubtotal;
    float Subtotal;
    float TacosSubtotal;
    float Total;
    int TotalItems;

    virtual void calcTotals()=0;

    virtual ~Order(){};



};

//child class 1

class ConsumerOrder:public Order{
private:
    float SALES_TAX_RATE;
public:
    string CustomerName;
    float SalesTax;
    void calcTotals() override;
    string ToString();

};

// child class 2

class CateringOrder: public Order
{

public:
    string CustomerCode;
    float DeliveryFee;
    bool PreferredCustomer;
    void Order::calcTotals(void) override;
    string ToString();

};

//other class

static class Validation
{
public:
    bool CheckCustomerCode();
    bool CheckCustomerType();
    float CheckDeliveryFee();
    int CheckItem();

};

now when i make object of base class then it shows error after compiling it.

bool Validation::CheckCustomerCode()
{
CateringOrder obj;

string tempCode = obj.CustomerCode;

return true;
}
1

1 Answers

0
votes

Well, the linker error you get would suggest that you never provided a definition for

void CateringOrder::calcTotals(void) {…}

Apart from that, writing something like this:

void Order::calcTotals(void) override;

in a class definition is not legal C++. While this non-standard syntax works with the Visual C++ compiler, it is kept around there only for compatibility reasons. The proper version would be to simply write

void calcTotals(void) override;