I receive this error when trying to compile a derived class. This my first time working with inherited classes so I am not sure what is wrong.
(edit: I have been working on the project and changed it somewhat. Also, here are the error messages from my compiler. Here is the entire thing if it helps https://repl.it/LYwt/8)
#ifndef SHOPPINGCART_H
#define SHOPPINGCART_H
#include <iostream>
#include <iomanip>
#include "Bag.h"
#include "item.h"
template<class ItemType>
class shoppingcart : public Bag<ItemType>
{
private:
float totalPrice;
public:
shoppingcart();
double getTotalPrice();
bool add(item);
bool remove(item);
};
#endif
header file:
#include "shoppingcart.h"
using namespace std;
template <class ItemType>
shoppingcart<ItemType>::shoppingcart() : totalPrice(0.00)
{
}
template <class ItemType>
bool shoppingcart<ItemType>::add(const item newProduct)
{
bool added = Bag<ItemType>::add(newProduct);
totalPrice = totalPrice + (newProduct.getitemQuantity() * newProduct.getitemPrice());
return added;
}
template <class ItemType>
bool shoppingcart<ItemType>::remove(const item aProduct)
{
bool removed = Bag<ItemType>::remove(aProduct);
totalPrice = totalPrice - (aProduct.getitemQuantity() * aProduct.getitemPrice());
return removed;
}
float price;
template <class ItemType>
double shoppingcart<ItemType>::getTotalPrice()
return totalPrice;
}
error messages:
shoppingcart2.cpp:5:1: error: 'shoppingcart' does not name a type shoppingcart::shoppingcart() : totalPrice(0.00) ^~~~~~~~~~~~
shoppingcart2.cpp:11:18: error: expected initializer before '<' token bool shoppingcart::add(const item newProduct) ^
shoppingcart2.cpp:21:18: error: expected initializer before '<' token bool shoppingcart::remove(const item aProduct) ^
shoppingcart2.cpp:31:20: error: expected initializer before '<' token double shoppingcart::getTotalPrice()
using namespace std;
in headers is bad practice. – Raindrop7shoppingcart
,ShoppingCart
, andshoppingCart
- different capitalization. – Bo Persson