title: undefined reference to object error
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class Part{
  public:
      std::string spec;
      Part(std::string str){
          this-&gt;spec = str;
      }
      std::string getSpec(){
          return spec;
      }
  };
  
  class Car{
  public:
      Part getEngine();
      Part getWheels();
      Part getBody();
  };
  
  
  class Benz:public Car{
  public:
      Part getEngine(){
          return Part("Benz Engine");
      }   
      Part getWheels(){
          return Part("Benz Wheels");
      }
      Part getBody(){
          return Part("Benz Body");
      }
  };
  
  class Audi:public Car{
  public:
      Part getEngine(){
          return Part("Audi Engine");
      }   
      Part getWheels(){
          return Part("Audi Wheels");
      }
      Part getBody(){
          return Part("Audi Body");
      }
  };
  
  class CarFactory{
  public:
      Car *pcar;
      Car *getCar(std::string carType){
          if (carType.compare("Benz") == 0){
              pcar = new Benz();
          }else if (carType.compare("Audi") == 0){
              pcar = new Audi();
          }
          return pcar;
      }
  };
  
  int main(){
      CarFactory *cf = new CarFactory();
      Car *mycar = cf-&gt;getCar("Benz");
      Part myCarBody = mycar-&gt;getBody();
      cout &lt;&lt;myCarBody.getSpec() &lt;&lt;endl;
      //cout &lt;&lt; mycar-&gt;getBody().getSpec() &lt;&lt;endl;
  }
  </code></pre>
  
  <p>In the above code getting, undefined reference to object error at line <I>Part myCarBody = mycar->getBody();</I> line of main function. Can you please help me for fixing this and also please explain the difference between <I>Car *mycar and Car mycar</I>. Which one to choose when?</p>
  
  <p>Thanks for the help.</p>