I have a uni assignment in which I have to implement a singly linked list that contains different objects that are derived from a common abstract base class called Shape.

I'll link to GitHub for the class implementation: [shapes.h](https://github.com/jkase/OOP-Assignment-3---Lists--inheritance-and-polymorphism/blob/master/shapes.h) , [shapes.cpp](https://github.com/jkase/OOP-Assignment-3---Lists--inheritance-and-polymorphism/blob/master/shapes.cpp). So far it consists of `Shape` and its derived class `Circle`. There'll also be `Rectangle`, `Point` and `Polygon` later.

I should now implement a singly linked list of these different kinds of shapes. So far I've come up with the following class prototype for the `List`-class and the `Node`-class:

```
class Node
{
public:
    Node() {}

    friend class ShapeList;

    private:
    Shape* data;
    Node* nextNode;
};

class ShapeList
{
public:
    ShapeList(){head = NULL;}
    void Append(Shape& inData);

private:
    Node* head;
};

```

Adding elements `void Append(Shape& inData)` to a `ShapeList`-object should be able to be called from main in the following style:

```
ShapeList list1;

list1.Append( Circle(5,5,5) );
list1.Append( Rectangle( 4, 10, 2, 4) );

```

Given this information, how should I go about implementing `void Append(Shape& inData)`? I've tried several different approaches, but haven't come up with the correct solution so far.

It's also completely possible that the parameter to `Append` should be something else than `(Shape& inData)`.

edit:

I've implemented `Append(Shape& inData)` but it works only sometimes: 

```
Circle circle1;
ShapeList list1;
list1.Append( circle1 );

```

but not with

```
ShapeList list1;
list1.Append ( Circle(5,5,5) )

```

So far my `Append()`-implementation looks as follows:

```
void ShapeList::Append(Shape& inData)
{
    //Create a new node
    Node* newNode = new Node();
    newNode->data=&inData;
    newNode->nextNode=NULL;

    //Create a temp pointer
    Node *tmp = head;

    if (tmp != NULL)
    {
        //Nodes already present in the list
        //Traverse to the end of the list
        while(tmp->nextNode != NULL)
            tmp = tmp->nextNode;

        tmp->nextNode=newNode;
    }

    else
        head=newNode;
}

```

Does that look ok to you guys?