title: C++ STL set of classes - compiler error error C2664
body: <p>Newbie programmer here trying to work out his homework. I'm trying to use a STL set of classes, but the compiler complains about my code.</p>
  
  <pre><code>car.h
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;time.h&gt;
  #include &lt;set&gt;
  
  class Car
  {
  private:
  
  std::string plateNumber;
  std::string description;
  std::string dateIn;
  std::string timeIn;
  
  public:
  Car() {};
  ~Car() {};
  Car(std::string plate, std::string desc)    
  {
      plateNumber = plate;
      description = desc;
  };
  
  void setPlateNumber(std::string plate) ;
  std::string getPlateNumber() const;
  
  void setDesc(std::string desc);
  
  void setTimeDateIn() ;
  std::string getTimeIn() const;
  std::string getDateIn() const;
  std::string getDesc() const;
  
  friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, Car &amp;c);
  
  };
  std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, Car&amp; c)  
  {
  os &lt;&lt; "Plate Number: " &lt;&lt; c.plateNumber &lt;&lt; ", Date In: " &lt;&lt; c.dateIn &lt;&lt; ", " &lt;&lt; 
  `"Time in: " &lt;&lt; c.timeIn &lt;&lt; "Description: " &lt;&lt; c.description &lt;&lt; std::endl;
  return os;
  }
  bool operator&lt; ( const Car&amp; lhs, const Car&amp; rhs) 
  {
  return ( lhs.getPlateNumber() &lt;  rhs.getPlateNumber() );
  };
  
  
  main.cpp
  
  #include "stdafx.h"
  #include &lt;iostream&gt; 
  #include &lt;set&gt;
  #include &lt;string&gt;
  #include "car.h"
  
  void carEnters(std::set&lt;Car&gt; g);
  void carLeaves(std::set&lt;Car&gt; g);
  void displayContents(std::set&lt;Car&gt; g);
  
  int main () 
  {
  char choice [80];
  
  // initialize the sets and iterators
  std::set&lt;Car&gt; garage;
  
  do  // Loop until user quits
  {
  std::cout &lt;&lt; 
   std::endl;                                 
      std::cout &lt;&lt; "Menu:" &lt;&lt; std::endl;
      std::cout &lt;&lt; "-----" &lt;&lt; std::endl;
      std::cout &lt;&lt; "'1' to enter a new car, or "    &lt;&lt; std::endl;
      std::cout &lt;&lt; "'2' to exit the front car, or " &lt;&lt; std::endl;
      std::cout &lt;&lt; "'3' to to list all the cars or." &lt;&lt; std::endl;
      std::cout &lt;&lt; "'0' to close the garage: "     &lt;&lt; std::endl;
      std::cin.getline( choice, 1, '\n');
  
      switch ( choice[0] )
      {
          case '0' :
  
              std::cout &lt;&lt; std::endl &lt;&lt; "Thanks for playing...\n";
              break;
  
          case '1' :
  
              carEnters(garage);
              break;
  
          case '2' :
  
              carLeaves(garage);
  
          case '3' :
  
              displayContents(garage);
              break;
  
          default:
              std::cout &lt;&lt; "I'm sorry, I didn't understand that.\n";
              break;
      }
  } while ( choice[0] != '0' );   // Loop again if the user hasn't quit.
  
  return 0;
  }
  
  void carEnters( std::set&lt;Car&gt; g)
  
  {
  // Car enters garage
  std::cout &lt;&lt; "Please enter the plate number:" &lt;&lt; std::endl;
  std::string plate;
  std::cin &gt;&gt; plate;
  std::cin.ignore();
  
  std::set&lt;Car&gt;::iterator findPlate;
  Car* lookup = new Car;
  lookup-&gt;setPlateNumber(plate);
  
  findPlate = g.find(*lookup);
  if (findPlate != g.end())   // Add car to garage
  {
      Car *currentCar = new Car ;             
      // Set car parameters
      std::cout &lt;&lt; "Please type the entering car's description &lt;Model, Color...  
   &gt; : " &lt;&lt; std::endl;
      char desc[80];
      std::cin.get(desc, 80 );
      std::cin.ignore();
      currentCar-&gt;setDesc(desc);
      currentCar-&gt;setTimeDateIn();
      currentCar-&gt;setPlateNumber(plate);
  
      g.insert(currentCar);
  }
  else // Plate is already in garage set
  {   
      std::cout &lt;&lt; "Sorry, this car is already in the garage!" &lt;&lt;    
   std::endl;     
  }
  }
  
  void carLeaves( std::set&lt;Car&gt; g)
  {
  std::string plate;
  std::cout &lt;&lt; "Which plate is leaving?" &lt;&lt; std::endl;
  std::cin &gt;&gt; plate;
  std::cin.ignore();
  
  // Find car's plate number in the garage set
  // for (findPlate=garageSet.begin(); findPlate !=garageSet.end(); findPlate++)
  std::set&lt;Car&gt;::iterator findPlate;
  Car lookup(plate,"");
  
  findPlate = g.find(lookup);
  if (findPlate != g.end())
  {
      // Display time in and then remove car from set of cars
      std::cout &lt;&lt; "Car out at " &lt;&lt; (*findPlate).getDateIn() &lt;&lt; ", " &lt;&lt; 
  (*findPlate).getTimeIn() &lt;&lt; std::endl;
      g.erase(findPlate);
  }
  else
  {
      std::cout &lt;&lt; "Car was not found in set of Cars!" &lt;&lt; std::endl;
  }
  }
  
  // Car class function implementation
  void Car::setPlateNumber(std::string p)
  {
  plateNumber = p;
  }   
  std::string Car::getPlateNumber() const 
  {
  return plateNumber;
  }
  void Car::setDesc(std::string d) 
  {
  description = d;
  }
  void Car::setTimeDateIn() 
  {
  char dat[9];
  char tim[9];
  
  _strdate_s(dat);
  _strtime_s(tim);
  
  dateIn=dat;
  timeIn=tim;
  } 
  std::string Car::getTimeIn() const
  {
  return timeIn;
  }
  std::string Car::getDateIn() const
  {
  return dateIn;
  }
  std::string Car::getDesc() const
  {
  return description;
  }
   // Display the car set
  void displayContents(std::set &lt;Car&gt; garage)
  {
  // function displays current contents of the parking garage.
  std::set &lt;Car&gt;::iterator carIndex;
  
  std::cout &lt;&lt; std::endl &lt;&lt; "Here are all the cars parked: " &lt;&lt; std::endl;
  for (carIndex = garage.begin();
       carIndex != garage.end();
       ++carIndex )
  {
      std::cout &lt;&lt; " " &lt;&lt; carIndex-&gt;getPlateNumber() &lt;&lt; ", Date In: " &lt;&lt; 
  carIndex-&gt;getDateIn() &lt;&lt; ", " &lt;&lt; "Time In: " &lt;&lt; carIndex-&gt;getTimeIn() &lt;&lt; "Description: 
  " &lt;&lt; carIndex-&gt;getDesc() &lt;&lt; std::endl;
  }
  }
  </code></pre>
  
  <p>The error I get from the compiler is this:
  xmemory(208): error C2664: 'Car::Car(const Car &amp;)' : cannot convert parameter 1 from 'Car *' to 'const Car &amp;'
            Reason: cannot convert from 'Car *' to 'const Car'
            No constructor could take the source type, or constructor overload resolution was ambiguous</p>
  
  <p>I'm not sure where I'm going wrong, would some please point out how my overload is incorrect?</p>
  
  <p>Thanks</p>