Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Iteratorisnotrecognizingfunctionofbaseclassc

I have two for loops which look like that

for(int unsigned i = 0; i < listOfOrder.size(); i ++){
        listOfOrder[i]->print();
        totalTax += listOfOrder[i]->getTax();
        totalPayment += listOfOrder[i]->getTotal();
        cout << "Total Tax Payable: RM" << totalTax <<endl;
        cout << "Total Payment: RM" << totalPayment <<endl;
    }

and

vector<Order *>::iterator iterOrder;
for(iterOrder = listOfOrder.begin(); iterOrder != listOfOrder.end(); iterOrder++){
        (*iterOrder)->print();
        totalTax += (*iterOrder)->getTax();
        totalPayment += (*iterOrder)->getTotal();
        cout << "Total Tax Payable: RM" << totalTax <<endl;
        cout << "Total Payment: RM" << totalPayment <<endl;
    }

listOfOrder is vector like this vector<Order*>listOfOrder; it holds vector of derived(or child) objects of Order class(base and abstract). print function is a virtual whereas getTax and getTotal functions are in only base(Order) class. First loop is working correctly, but I am trying to do it with an ITERATOR. Unfortunately when I try to do it with an iterator(second loop), compiler is giving me an error that states "getTax and getTotal could not be resolved". What could I possibly doing incorrectly in second loop? I hope provided info is enough for this question, otherwise i can provide more.

Comments