I got a abstract baseclass "Furniture" with 1 subclass "Bookcase".
In a handler.cpp I created double pointer; Furniture** furnitures. So when I want to add stuff, i can use something like this;
void FurnitureHandler::addBookcase(string name, float price, int stock, string material, float height)
{
this->furniture[this->nrOfFurniture] = new Bookcase(name, price, stock, material, height);
this->nrOfFurniture++;
}
However, "new" is highlighted and I get 'error C2243: 'type cast' : conversion from 'Bookcase *' to 'Furniture *' exists, but is inaccessible'. What do I have to do to make it work?
codes;
#ifndef __FURNITURE_H__
#define __FURNITURE_H__
#include<string>
#include<iostream>
using namespace std;
class Furniture
{
private:
string name;
float price;
int stock;
public:
void print()const;
virtual void printSpec()const =0;
public:
Furniture(string name = "", float price = 0.0f, int stock = 0);
virtual ~Furniture();
};
#endif
Furniture::Furniture(string name, float price, int stock)
{
this->name=name;
this->price=price;
this->stock=stock;
}
Furniture::~Furniture(){}
void Furniture::print()const
{
cout<<"All furnitures in memory:"<<endl;
this->printSpec();
}
#ifndef __BOOKCASE_H__
#define __BOOKCASE_H__
#include "Furniture.h"
class Bookcase : Furniture
{
private:
string material;
float height;
public:
Bookcase(string, float, int, string, float);
virtual ~Bookcase();
virtual void printSpec()const;
};
#endif
#include "Bookcase.h"
Bookcase::Bookcase(string name, float price, int stock, string material, float height) : Furniture(name, price, stock)
{
this->material = material;
this->height = height;
}
Bookcase::~Bookcase(){}
void Bookcase::printSpec()const
{
cout<<material<<", "<<height<<endl;
}