how to use lists with abstract class
#include<iostream>
#include<string>
using namespace std;
class Sale
{
public:
Sale(double _price=0,string _type=""):price(_price),type(_type) { }
virtual void print() const =0;
protected:
double price;
string type;
};
class Book:public Sale
{
public:
Book(double _price=0,string _type="",string _title=""):Sale(_price,_type),title(_title) { }
void print() const
{
cout<<"title: "<<title<<endl;
cout<<"price: "<<price<<endl;
cout<<"type: "<<type<<endl;
}
private:
string title;
};
#######################################
#include"sale.h"
#include<iostream>
#include<list>
using namespace std;
int main()
{
list<Sale *> myList;
list<Sale *>::iterator myIt;
myList.push_back(new Book(30,"romance","bir ask hikayesi"));
myList.push_back(new Book(25,"action","matrix"));
myList.push_front(new Book(5,"comedy","arif"));
cout<<"my shopping cart"<<endl;
for(myIt=myList.begin(); myIt!=myList.end(); myIt++)
(*myIt)->print();
system("pause");
return 0;
}
##################################