So I have a problem with an abstract class!
This is the Product.h
#ifndef PRODUCT_H
#define PRODUCT_H
#include <string>
using namespace std;
class Product
{
private:
string description;
int d,m,y;
float weight;
public:
Product();
Product(string description,int d,int m,int y, float weight);
void print();
virtual bool isExpiring()=0;
};
#endif
This is Product.cpp
#include "Product.h"
#include <string>
#include <iostream>
using namespace std;
Product::Product()
{
description="";
d=0;
m=0;
y=0;
weight=0.0;
}
Product::Product(string description,int d,int m,int y, float weight)
{
this->description=description;
this->d=d;
this->m=m;
this->y=y;
this->weight=weight;
}
void Product::print()
{
cout << "Description: " << description<<endl;
cout << "Expiration date: " << d <<"/" << m << "/" << y << endl;
cout << "Weight: " << weight << endl;
}
This is ShortTermProduct.h
#ifndef SHORTTERMPRODUCT_H
#define SHORTTERMPRODUCT_H
#include "Product.h"
class ShortTermProduct : public Product
{
public:
ShortTermProduct();
void Print();
bool isExpiring();
};
#endif
This is LongTermProduct.h
#ifndef LONGTERMPRODUCT_H
#define LONGTERMPRODUCT_H
#include "ShortTermProduct.h"
#include <string>
using namespace std;
class LongTermProduct
{
private:
int lifetime;
string open, open_date;
public:
LongTermProduct(int lifetime,string open,string open_date);
void print();
bool isExpiring();
};
#endif
And finally this is Fridge.h
#ifndef FRIDGE_H
#define FRIDGE_H
#include "LongTermProduct.h"
class Fridge : public LongTermProduct
{
private:
Product products[10];
public:
fridge();
void addShortTermProduct (ShortTermProduct p);
void addLongTermProduct (LongTermProduct p);
void printFridgeProducts();
bool isExpiring();
};
#endif
The errors I am getting are these:
- [Error] invalid abstract type 'Product' for 'products'
- [Error] cannot declare field 'Fridge::products' to be of abstract type 'Product'
Any help would be grate !Thanks in advance !