m_arian 36 Newbie Poster

Hi I'm new to coding. Can someone please help with a linked list problem. I'm getting numbers for output, I think they are addresses. The output I'm getting is:
HEAD CODE
-12086434400
1080131584
TAIL CODE

The output I need is:
HEAD CODE
<rect x="0" y="0" width ="200" height="200" stroke-width="2" stroke="red" fill="none" />
<rect x="14" y="140" width ="140" height="14" stroke-width="2" stroke="red" fill="none" />
TAIL CODE

I know it has something to do with the switch. I know that code is right but I'm not utilising it.

Thanks

#include <iostream>
#include <string>
#include <cassert>
using namespace std;

class Path
{
public:
//stub
}; // Path

class Circle
{
public:
//stub
}; // Circle

class Rectangle
{
public:
    Rectangle();
    Rectangle(double x, double y, double w, double h, string c = "red", string f = "none");
    void Print(ostream & out) const;
private:
    double rx, ry, width, height;
    string colour, fill;
};

ostream & operator<<(ostream & out, const Rectangle & rectangle);


class DataType
{
 public:
  enum { EMPTY, PATH, CIRCLE, RECTANGLE } SVGObj;
  union
  {
    Path *path;
    Circle *circle;
    Rectangle *rectangle;
  };
  DataType();
  DataType(const DataType &);
  DataType(const Circle & obj);
  DataType(const Path & obj);
  DataType(const Rectangle & obj);

};


struct LNode
{
  DataType data;
  LNode *next;
};

typedef LNode* LNodePtr;


class Svg
{
  public:
    Svg(double w, double h);
    ~Svg(); //destructor
    void Head(ostream & out) const;
    void Tail(ostream & out) const;
    void Print(ostream & out) const;
    void Append(const Path & obj);
    void Append(const Circle …
m_arian 36 Newbie Poster

Hi

This is my first DaniWeb post so I hope I get it right.
My problem is homework. I have almost got it but I'm having trouble with the pointers. The entire program will output svg code but I've tried to leave out as much as I can to reduce the amount of code. There are a number of shape classes, two have been left as stubs. One Svg class and a DataType class. The DataType class has an enumeration of shapes and a union of pointers. This is where I am getting confused. I can't change the way the driver works because code was supplied with the assignment to run the program. I know there is something wrong with the Append functions but I can't work out how to fix them. When I compile, I get the appended rectangles appearing properly above the svg header, then the header, then "89892" which I presume is an address, then the rectangle addresses, then an error "*** glibc detected *** free(): invalid pointer: 0xb7feaff4" then the closing svg tag and the word Aborted.

The output should be: the svg header, then the rectangle tags, then the svg end tag.
Thanks in advance

#include <iomanip>	// output formatting
#include <vector>	// vector class
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
using namespace std;


class Path
{
public:
//stub
}; // Path

class Circle
{
public:
//stub
}; // Circle

class Rectangle
{
public:
    Rectangle();
    Rectangle(int x, int …
Ancient Dragon commented: thanks for using code tags +36