Drink.hpp
#ifndef DRINK_HPP
#define DRINK_HPP
#include <iostream>
#include "Grocery.hpp"
using namespace std;
class Drink : public Grocery
{
public:
Drink(string name, double price, double weight);
void updateCost(); // updates total_price_
};
#endif
DRINK.CPP
#include <iostream>
#include "Drink.hpp"
using namespace std;
Drink:: Drink(string name, double price, double weight): Grocery(name, price, weight){};
void Drink::updateCost()
{
/*
total_price_ <- product of: quantity, weight per liter,
and price per liter */
total_price_ = quantity_ * ((unit_weight_ * 16) / 33.814) * unit_price_;
cout << total_price_ << endl;
}
Which inherits from Grocery.HPP
#define GROCERY_HPP
#include <iostream>
#include <string>
class Grocery
{
public:
/**
Set the quantity_ to 1 and total_price_ to 0. Set name_, unit_price_, and unit_weight_ to what was given by the user.
*/
Grocery(std::string name, double price, double weight);
/**
Increase quantity_ by one and call updateCost().
If the function works, return true.
*/
bool incrementQuantity();
/**
Decrease the quantity by one if there is at least a quantity of 1,
and call updateCost().
If the function works, return true
*/
bool decrementQuantity();
double getTotalPrice() const; // returns total_price_
double getUnitPrice() const; // returns unit_cost_
double getUnitWeight() const; // returns unit_weight_
int getQuantity() const; // returns quantity_
std::string getName() const; // returns name_
bool operator==(const Grocery &rhs) const; // Comparison operator overload
protected:
/*
Calculates the total cost of the items in the class.
*/
virtual void updateCost() = 0;
std::string name_;
int quantity_;
double unit_price_;
double unit_weight_;
double total_price_;
}; // end Grocery
#endif
im getting the errors:
undefined reference to `Drink::Drink(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, double)'
undefined reference to `Drink::updateCost()'
undefined reference to `vtable for Drink'
collect2.exe: error: ld returned 1 exit status
Drink is a derived class of base class Grocery, and has other derived classes which get the same error when ran. I've tried including the cpp files in the headers and it doesnt seem to work. i also get the same error compiling the filesindividually and still getting the same errors.
Aucun commentaire:
Enregistrer un commentaire