title: C++ Linked List of Objects
body: <p>I have a class whose objects must be added to a linked list. The objects are only created within a non-member function. I have to admit, linked lists make no sense to me at all, and yes, I've read other questions on this forum and still can't figure it out. </p>
  
  <p>How would I go about 1. creating this linked list 2. adding an object to this list each time one is created and 3. be able to delete every node of the list?</p>
  
  <p>This is my class:</p>
  
  <pre><code>class ShirtOrder
  {
      friend ostream&amp; operator&lt;&lt;(ostream &amp;os, const ShirtOrder &amp;rhsObj);
  
  private:
      // the data members below are required (you may change identifiers)
      // there is no need for additional data members
      int orderYear, orderMonth, orderDay;
      char printMethod; // 's', 'i', or 'e'
      string message;
      int mediums; // number of medium shirts ordered
      int larges; // number of large shirts ordered
      int xls; // number of XL shirts ordered
      string shirtColor;
      string inkColor;
      string orderID;
      string region;
      string nameAndEmail;
  
      ShirtOrder* next; // new for P5
  
  public:
      ShirtOrder(); // default constructor
  
      ShirtOrder(int orderYear, int orderMonth, int orderDay,
                 char printMethod, string message, int mediums, int larges, int xls,
                 string shirtColor, string inkColor, string orderID,
                 string region, string nameAndEmail,
                 ShirtOrder *soPtr = NULL);
  
      ShirtOrder(const ShirtOrder &amp;otherObj);
  
      ~ShirtOrder(); // destructor                      // New for P5 (may not be in-line)
  
      ShirtOrder* getNext() const {return next;}        // New for P5 (may be in-line)
  
      void setNext(ShirtOrder* soPtr) {next = soPtr;}   // New for P5 (may be in-line)
  
      double getBlankCost() const;
      double getPrintingCost() const;
      double getTotalCost() const;
  
      int    getLetterCount() const;
      char   getPrintMethod() const {return printMethod;}
      int    getOrderYear() const {return orderYear;}
      int    getOrderMonth() const {return orderMonth;}
      int    getOrderDay() const {return orderDay;}
      int    getMediums() const {return mediums;}
      int    getLarges() const {return larges;}
      int    getXls() const{return xls;}
  
      string getShirtColor() const {return shirtColor;}
      string getInkColor() const {return inkColor;}
      string getOrderID() const {return orderID;}
      string getRegion() const {return region;}
      string getNameAndEmail() const {return nameAndEmail;}
      string getMessage() const {return message;}
  
      void  setOrderYear (int orderYear) {this-&gt;orderYear = orderYear;}
      void  setOrderMonth (int orderMonth) {this-&gt;orderMonth = orderMonth;}
      void  setOrderDay (int orderDay) {this-&gt;orderDay = orderDay;}
      void  setPrintMethod (char printMethod) {this-&gt;printMethod = printMethod;}
      void  setMessage (string message) {this-&gt;message = message; }
      void  setMediums (int mediums) {this-&gt;mediums = mediums;}
      void  setLarges (int larges) {this-&gt;larges = larges;}
      void  setXls (int xls) {this-&gt;xls = xls;}
      void  setShirtColor (string shirtColor) {this-&gt;shirtColor = shirtColor;}
      void  setInkColor (string inkColor) {this-&gt;inkColor = inkColor;}
      void  setOrderID (string orderID) {this-&gt;orderID = orderID;}
      void  setRegion (string region) {this-&gt;region = region;}
      void  setNameAndEmail (string nameAndEmail) {this-&gt;nameAndEmail = nameAndEmail;}
  
  };
  </code></pre>
  
  <p>So say an object of this class is created within a non-member function. How do I create a list of such objects, and add each object to the end of the list? Thanks!</p>