Hi!
I was hoping for some advice on how best to create a single doubly-linked list which could contain all of the different types of classes I have.
This is the code I have written so far....
shape.h:
class Shape
{
public:
Shape (int l=0, int h=0) : length(l), height(h) {}
private:
int length;
int height;
protected:
};
class Square : public Shape
{
public:
private:
int side1;
int side2;
int side3;
int side4;
}
class Triangle : public Shape
{
public:
private:
int side1;
int side2;
int side3;
}
main.cpp:
#include <iostream>
#include "vessel.h"
using namespace std;
int main()
{
int x;
int y;
cout << "enter the heighe" << endl;
cin >> x;
cout << "enter he length" << endl;
cin >> y;
Shape square(x,y);
system ("PAUSE");
return 0;
}
I've read loads these last couple of days on doubly-linked lists, but am not understanding the role of Templates.
Would use of a Template allow me to store the 3 different types of classes I have within a single doubly linked list?
I code I have written concerns me as I am creating an object of type Shape, but I'm thinking I should be storing pointers to the objects, not the objects themselves within the list.
If anyone can offer me some direction and advice on the matter it would be most appreciated :)
Many thanks!
Carrots.