title: C++ operator overloading input operator >> with object outside class as member
body: <p>This is homework--I am having issues defining my input >> operator overload for my Customer.h file, where an object from another class is a member of this class.  I will be using the input operator to read data in from a text file and output it to a BinaryTree.  We have a Customer class and an Address class.  Address is a member of Customer (part of Customer's constructor).  I have to read in the file which contains:
  CustomerID
  CustomerName
  AddressStreet
  AddressCity
  AddressZip</p>
  
  <p>Customer's constructor is Customer(int custID, string custName, Address* address) so I'm having problems with my input overload in the Customer class, where I have to read in the address data as the street, city, state, zip but store it as the Customer address.  I may have done something wrong with my class declarations, too.  Here is what I have:</p>
  
  <p>Customer.h:</p>
  
  <pre><code>#pragma once
  #include &lt;string&gt;
  #include "Address.h"
  
  using namespace std;
  
  class Customer
  {
  private:
  //Attributes for customers
  int custID;
  string custName;
  Address* address;
  
  public:
  //Constructors for Customer
  Customer();
  Customer(int, string, Address*);
  ~Customer();
  //Setters for Customer
  void setCustID(int);
  void setCustName(string);
  void setCustAddress(Address*);
  //Getters for Customer
  int getCustID() {return custID;}
  string getCustName() {return custName;}
  
  //Operator overloads
  bool operator&gt;(Customer obj) {return custID &gt; obj.custID;}
  bool operator&lt;(Customer obj) {return custID &lt; obj.custID;}
  bool operator==(Customer obj) {return custID == obj.custID;}
  
  //Operator overloads for input
  friend istream &amp;operator&gt;&gt;(istream &amp;input, Customer &amp;customer) {
      input &gt;&gt; customer.custID &gt;&gt; customer.custName &gt;&gt; /*?????  Here's where I can't figure out what to call for the address street, city, state, zip; */ &lt;&lt; endl;
      return input;
  }
  
  //Operator overloads for output
  friend ostream &amp;operator&lt;&lt;(ostream &amp;output, Customer &amp;customer) {
      output &lt;&lt; "CustID: " &lt;&lt; customer.custID &lt;&lt; endl &lt;&lt; "Customer Name: " &lt;&lt; customer.custName &lt;&lt; endl &lt;&lt; "Customer Address: " &lt;&lt; customer.address &lt;&lt; endl;
      return output;
  }
  
  };
  </code></pre>
  
  <p>Customer.cpp:</p>
  
  <pre><code>#include "Customer.h"
  
  //Customer no arg constructor
  Customer::Customer()
  {
  custID = 0;
  custName = "";
  }
  
  //Customer constructor
  Customer::Customer(int custID, string custName, Address* address)
  {
  this-&gt;custID = custID;
  this-&gt;custName = custName;
  this-&gt;address = address;
  }
  
  //Customer destructor
  Customer::~Customer()
  {
  
  }
  </code></pre>
  
  <p>Address.h:</p>
  
  <pre><code>#pragma once
  #include &lt;string&gt;
  
  using namespace std;
  
  class Address 
  {
  private:
  string street;
  string city;
  string state;
  string zip;
  
  public:
  //Constructors for address
  Address();
  Address(string, string, string, string);
  ~Address();
  //Setters for address
  void setAddressStreet(string);
  void setAddressCity(string);
  void setAddressState(string);
  void setAddressZip(string);
  //Getters for address
  string getAddressStreet() {return street;}
  string getAddressCity() {return city;}
  string getAddressState() {return state;}
  string getAddressZip() {return zip;}
  
  //Operator overload for input
  friend istream &amp;operator&gt;&gt;(istream &amp;input, Address &amp;address) {
      input &gt;&gt; address.street &gt;&gt; address.city &gt;&gt; address.state &gt;&gt; address.zip;
      return input;
  }
  //Operator overload for output
  friend ostream &amp;operator&lt;&lt;(ostream &amp;output, Address &amp;address) {
      output &lt;&lt; "Street: " &lt;&lt; address.street &lt;&lt; endl &lt;&lt; "City: " &lt;&lt; address.city &lt;&lt; endl &lt;&lt; "State: " &lt;&lt; address.state &lt;&lt; endl &lt;&lt; "Zip: " &lt;&lt; address.zip &lt;&lt; endl;
      return output;
  }
  };
  </code></pre>
  
  <p>Address.cpp:</p>
  
  <pre><code>#include "Address.h"
  
  //Address no arg constructor
  Address::Address()
  {
  street = "";
  city = "";
  state = "";
  zip = "";
  }
  
  //Address constructor
  Address::Address(string street, string city, string state, string zip)
  {
  this-&gt;street = street;
  this-&gt;city = city;
  this-&gt;state = state;
  this-&gt;zip = zip;
  }
  
  //Address destructor
  Address::~Address()
  {
  }
  </code></pre>