title: c++ abstract base class and inheritance
body: <p>I am trying to get this program to compile but i'm getting all sorts of weird errors
  its saying that i'm making and instants of an abstract base class. but i believe it's only saying that because when i declare the derived class that tries to make an instances of the base class which is abstract.</p>
  
  <p>Im getting multiple declaration for some methods as well.</p>
  
  <p>Thank you so much for your help. im so lost.</p>
  
  <p>the reason i included everything is because i really don't know what is causing the problems. The error msgs are at the bottom if you want to specifically see what files i'm getting the errors in.</p>
  
  <pre><code>//main.cpp
  #include &lt;iostream&gt;
  #include "Polygon.h"
  using namespace std;
   int main() {
      Polygon rect("Rectangle", 4);
      rect(0) = Point(1, 1);
      rect(1) = Point(2, 1);
      rect(2) = Point(2, 4);
      rect(3) = Point(1, 4);
  
      cout &lt;&lt; rect &lt;&lt; endl;
  
      return 0;
   }
  //point.cpp
  #include&lt;ostream&gt;
  #include"point.h"
  using namespace std;
  
  Point::Point()
  {
    set_x(0);
    set_y(0);
  }
  
  Point::Point(double varX, double varY)
  {
    set_x(varX);
    set_y(varY);
  }
  
  void Point::set_x(double var)
  {
    x=var;
  }
  
  void Point::set_y(double var)
  {
    y=var;
  }
  
  ostream&amp; Point::display(ostream&amp; os) const
  {
   os &lt;&lt; '(' &lt;&lt; x &lt;&lt; ',' &lt;&lt; y &lt;&lt; ')' &lt;&lt;endl;
   return os;
  }
  
  friend ostream&amp; operator&lt;&lt;(ostream&amp; os,Point&amp; a)
  {
    a.display(os);
  }
  
  double Point::xget()
  {
   return x;
  }
  double Point::yget()
  {
    return y;
  }
  
  Point&amp; operator+(Point&amp; b)
  {
    double tempX=x()+b.x();
    double tempY=y()+b.y();
    Point c(tempX,tempY);
    return *c;
  }
  
  Point&amp; operator/(Point&amp; o,int value)
  {
    double tempX=o.x()/value;
    double tempY=o.y()/value;
    Point c(tempX,tempY);
    return *c;
  }
  //point.h
  #ifndef _point_h
  #define _point_h
  class Point : public Showable
  {
  double x;
  double y;
  public:
  Point();
  Point(double,double);
  ostream&amp; display(ostream&amp;) const;
  double xget();
  double yget();
  void set_x(double);
  void set_y(double);
  friend ostream&amp; operator&lt;&lt;(ostream&amp;,Point&amp;);
  };
  
  Point&amp; operator+(Point&amp;);
  Point&amp; operator/(Point&amp;,int);
  #endif
  //polygon.cpp
  //abstract Base Classes
  #include &lt;iostream&gt;
  #include "Polygon.h"
  #include "point.h"
  #include "shape.h"
  using namespace std;
  
  Polygon::Polygon(char* str , int V):Shape(str)
  {
    points=V;
    Point* vertex= new Point[V];
  }
  
  Point&amp; Polygon::operator()(int i)
  {
    return vertex[i];
  }
  
  int Polygon::pointsNum()
  {
   return points;
  }
  
  Polygon&amp; Polygon::operator=(Polygon&amp; b)
  {
    points=b.pointsNum();
    if(vertex)
    delete[] vertex;
  
    if(this!=&amp;b &amp;&amp; b!=NULL)
    {
      vertex=new Point[b.pointNum()];
      for(int i=0;i&lt;b.pointNum();i++)
      {
        vertex[i]=b.vertex[i];
      }
    }
    else
    {
      vertex=NULL;
    }
    return *this;
  }
  ostream&amp; Polygon::display(ostream&amp; os) const
  {
    os &lt;&lt; (Shape)(*this) &lt;&lt;" Centroid " &lt;&lt; centroid();
  }
  
  friend ostream&amp; operator&lt;&lt;(ostream&amp; os,Polygon&amp; a)
  {
    a.display(os);
    return os;
  }
  
  
  Point&amp; Polygon::centroid() const
  {
    int tempX=0,tempY=0;
    for(int i=0;i&lt;points;i++)
    {
      tempX+= vertex[i].xget();
    }
    for(int i=0;i&lt;points;i++)
    {
      tempY+= vertex[i].yget();
    }
    Point c(tempX/points,tempY/points);
    return *c;
  }
  //polygon.h
  #ifndef _polygon_h
  #define _polygon_h
  #include "shape.h"
  #include "point.h"
  
  class Polygon : public Shape
  {
    int points;
    Point* vertex;
    public:
    Polygon(char* , int);
    Point&amp; operator()(int);
    Polygon&amp; Polygon::operator=(Polygon&amp; b);
    int pointsNum();
    ostream&amp; display(ostream&amp; os) const;
    Point&amp; centroid() const;
    friend ostream&amp; operator&lt;&lt;(ostream&amp;,Polygon&amp;);
  };
  
  
  #endif
  //shape.cpp
  #include&lt;cstring&gt;
  #include&lt;ostream&gt;
  #include "shape.h"
  using namespace std;
  Shape::Shape()
  {
    name[0]='\0';
  }
  Shape::Shape(char* str)
  {
    strcpy(name,str);
  }
  
  ostream&amp; Shape::display(ostream&amp; os) const
  {
    os &lt;&lt; name;
    return os;
  }
  
  char* Shape::nameget()
  {
    return name;
  }
  
  Shape&amp; operator=(Shape&amp; a)
  {
    strcpy(name,a.nameget());
  }
  //shape.h
  #ifndef _shape_h
  #define _shape_h
  #include "showable.h"
  #include "point.h"
  class Shape : public Showable
  {
    char name[30+1];
    public:
    Shape();
    Shape(char*);
    ostream&amp; display(ostream&amp;) const;
    char* nameget();
    virtual Point&amp; centroid() const=0;
  };
  #endif
  //showable.cpp
  #include&lt;ostream&gt;
  #include "showable.h"
  using namespace std;
  
  ostream&amp; operator&lt;&lt;(ostream&amp; os,Showable&amp; a)
  {
    a.display(os);
  }
  //showable.h
  #ifndef _showable_h
  #define _showable_h
  class Showable
  {
    public:
    virtual ostream&amp; display(ostream&amp;) const=0;
  
  };
  
  ostream&amp; operator&lt;&lt;(ostream&amp; os, Showable&amp;);
  #endif
  //main.cpp
  #include &lt;iostream&gt;
  #include "Polygon.h"
  using namespace std;
   int main() {
      Polygon rect("Rectangle", 4);
      rect(0) = Point(1, 1);
      rect(1) = Point(2, 1);
      rect(2) = Point(2, 4);
      rect(3) = Point(1, 4);
  
      cout &lt;&lt; rect &lt;&lt; endl;
  
      return 0;
   }
  //point.cpp
  #include&lt;ostream&gt;
  #include"point.h"
  using namespace std;
  
  Point::Point()
  {
    set_x(0);
    set_y(0);
  }
  
  Point::Point(double varX, double varY)
  {
    set_x(varX);
    set_y(varY);
  }
  
  void Point::set_x(double var)
  {
    x=var;
  }
  
  void Point::set_y(double var)
  {
    y=var;
  }
  
  ostream&amp; Point::display(ostream&amp; os) const
  {
   os &lt;&lt; '(' &lt;&lt; x &lt;&lt; ',' &lt;&lt; y &lt;&lt; ')' &lt;&lt;endl;
   return os;
  }
  
  friend ostream&amp; operator&lt;&lt;(ostream&amp; os,Point&amp; a)
  {
    a.display(os);
  }
  
  double Point::xget()
  {
   return x;
  }
  double Point::yget()
  {
    return y;
  }
  
  Point&amp; operator+(Point&amp; b)
  {
    double tempX=x()+b.x();
    double tempY=y()+b.y();
    Point c(tempX,tempY);
    return *c;
  }
  
  Point&amp; operator/(Point&amp; o,int value)
  {
    double tempX=o.x()/value;
    double tempY=o.y()/value;
    Point c(tempX,tempY);
    return *c;
  }
  //point.h
  #ifndef _point_h
  #define _point_h
  class Point : public Showable
  {
  double x;
  double y;
  public:
  Point();
  Point(double,double);
  ostream&amp; display(ostream&amp;) const;
  double xget();
  double yget();
  void set_x(double);
  void set_y(double);
  friend ostream&amp; operator&lt;&lt;(ostream&amp;,Point&amp;);
  };
  
  Point&amp; operator+(Point&amp;);
  Point&amp; operator/(Point&amp;,int);
  #endif
  //polygon.cpp
  //abstract Base Classes
  #include &lt;iostream&gt;
  #include "Polygon.h"
  #include "point.h"
  #include "shape.h"
  using namespace std;
  
  Polygon::Polygon(char* str , int V):Shape(str)
  {
    points=V;
    Point* vertex= new Point[V];
  }
  
  Point&amp; Polygon::operator()(int i)
  {
    return vertex[i];
  }
  
  int Polygon::pointsNum()
  {
   return points;
  }
  
  Polygon&amp; Polygon::operator=(Polygon&amp; b)
  {
    points=b.pointsNum();
    if(vertex)
    delete[] vertex;
  
    if(this!=&amp;b &amp;&amp; b!=NULL)
    {
      vertex=new Point[b.pointNum()];
      for(int i=0;i&lt;b.pointNum();i++)
      {
        vertex[i]=b.vertex[i];
      }
    }
    else
    {
      vertex=NULL;
    }
    return *this;
  }
  ostream&amp; Polygon::display(ostream&amp; os) const
  {
    os &lt;&lt; (Shape)(*this) &lt;&lt;" Centroid " &lt;&lt; centroid();
  }
  
  friend ostream&amp; operator&lt;&lt;(ostream&amp; os,Polygon&amp; a)
  {
    a.display(os);
    return os;
  }
  
  
  Point&amp; Polygon::centroid() const
  {
    int tempX=0,tempY=0;
    for(int i=0;i&lt;points;i++)
    {
      tempX+= vertex[i].xget();
    }
    for(int i=0;i&lt;points;i++)
    {
      tempY+= vertex[i].yget();
    }
    Point c(tempX/points,tempY/points);
    return *c;
  }
  //polygon.h
  #ifndef _polygon_h
  #define _polygon_h
  #include "shape.h"
  #include "point.h"
  
  class Polygon : public Shape
  {
    int points;
    Point* vertex;
    public:
    Polygon(char* , int);
    Point&amp; operator()(int);
    Polygon&amp; Polygon::operator=(Polygon&amp; b);
    int pointsNum();
    ostream&amp; display(ostream&amp; os) const;
    Point&amp; centroid() const;
    friend ostream&amp; operator&lt;&lt;(ostream&amp;,Polygon&amp;);
  };
  
  
  #endif
  //shape.cpp
  #include&lt;cstring&gt;
  #include&lt;ostream&gt;
  #include "shape.h"
  using namespace std;
  Shape::Shape()
  {
    name[0]='\0';
  }
  Shape::Shape(char* str)
  {
    strcpy(name,str);
  }
  
  ostream&amp; Shape::display(ostream&amp; os) const
  {
    os &lt;&lt; name;
    return os;
  }
  
  char* Shape::nameget()
  {
    return name;
  }
  
  Shape&amp; operator=(Shape&amp; a)
  {
    strcpy(name,a.nameget());
  }
  //shape.h
  #ifndef _shape_h
  #define _shape_h
  #include "showable.h"
  #include "point.h"
  class Shape : public Showable
  {
    char name[30+1];
    public:
    Shape();
    Shape(char*);
    ostream&amp; display(ostream&amp;) const;
    char* nameget();
    virtual Point&amp; centroid() const=0;
  };
  #endif
  //showable.cpp
  #include&lt;ostream&gt;
  #include "showable.h"
  using namespace std;
  
  ostream&amp; operator&lt;&lt;(ostream&amp; os,Showable&amp; a)
  {
    a.display(os);
  }
  //showable.h
  #ifndef _showable_h
  #define _showable_h
  class Showable
  {
    public:
    virtual ostream&amp; display(ostream&amp;) const=0;
  
  };
  
  ostream&amp; operator&lt;&lt;(ostream&amp; os, Showable&amp;);
  #endif
  //main.cpp
  
  32 main.cpp point.cpp Polygon.cpp shape.cpp showable.cpp
  Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
  main.cpp:
  Error E2462 showable.h 8: 'virtual' can only be used with non-template memb
  er functions
  Error E2303 showable.h 8: Type name expected
  Error E2139 showable.h 8: Declaration missing ;
  Error E2141 showable.h 12: Declaration syntax error
  Error E2303 point.h 12: Type name expected
  Error E2139 point.h 12: Declaration missing ;
  Error E2061 point.h 17: Friends must be functions or classes
  Error E2139 point.h 17: Declaration missing ;
  Error E2321 point.h 18: Declaration does not specify a tag or an identifier
  
  Error E2303 shape.h 13: Type name expected
  Error E2139 shape.h 13: Declaration missing ;
  Error E2303 Polygon.h 17: Type name expected
  Error E2139 Polygon.h 17: Declaration missing ;
  Error E2061 Polygon.h 19: Friends must be functions or classes
  Error E2139 Polygon.h 19: Declaration missing ;
  Error E2321 Polygon.h 20: Declaration does not specify a tag or an identifi
  er
  Error E2094 main.cpp 13: 'operator&lt;&lt;' not implemented in type 'std::ostream
  ' for arguments of type 'Polygon' in function main()
  *** 17 errors in Compile ***
  point.cpp:
  Error E2303 point.h 6: Type name expected
  Error E2303 point.h 12: Type name expected
  Error E2139 point.h 12: Declaration missing ;
  Error E2061 point.h 17: Friends must be functions or classes
  Error E2139 point.h 17: Declaration missing ;
  Error E2321 point.h 18: Declaration does not specify a tag or an identifier
  
  Error E2316 point.cpp 29: 'display' is not a member of 'Point'
  *** 7 errors in Compile ***
  Polygon.cpp:
  Error E2462 showable.h 8: 'virtual' can only be used with non-template memb
  er functions
  Error E2303 showable.h 8: Type name expected
  Error E2139 showable.h 8: Declaration missing ;
  Error E2141 showable.h 12: Declaration syntax error
  Error E2303 point.h 12: Type name expected
  Error E2139 point.h 12: Declaration missing ;
  Error E2061 point.h 17: Friends must be functions or classes
  Error E2139 point.h 17: Declaration missing ;
  Error E2321 point.h 18: Declaration does not specify a tag or an identifier
  
  Error E2303 shape.h 13: Type name expected
  Error E2139 shape.h 13: Declaration missing ;
  Error E2303 Polygon.h 17: Type name expected
  Error E2139 Polygon.h 17: Declaration missing ;
  Error E2061 Polygon.h 19: Friends must be functions or classes
  Error E2139 Polygon.h 19: Declaration missing ;
  Error E2321 Polygon.h 20: Declaration does not specify a tag or an identifi
  er
  Warning W8004 Polygon.cpp 14: 'vertex' is assigned a value that is never us
  ed in function Polygon::Polygon(char *,int)
  Error E2094 Polygon.cpp 32: 'operator!=' not implemented in type 'Polygon'
  for arguments of type 'int' in function Polygon::operator =(Polygon &amp;)
  Error E2316 Polygon.cpp 34: 'pointNum' is not a member of 'Polygon' in func
  tion Polygon::operator =(Polygon &amp;)
  Error E2316 Polygon.cpp 35: 'pointNum' is not a member of 'Polygon' in func
  tion Polygon::operator =(Polygon &amp;)
  Error E2015 Polygon.cpp 46: Ambiguity between 'ostream' and 'std::ostream'
  Error E2238 Polygon.cpp 46: Multiple declaration for 'ostream'
  Error E2344 showable.h 12: Earlier declaration of 'ostream'
  Error E2141 Polygon.cpp 46: Declaration syntax error
  *** 23 errors in Compile ***
  shape.cpp:
  Error E2462 showable.h 8: 'virtual' can only be used with non-template memb
  er functions
  Error E2303 showable.h 8: Type name expected
  Error E2139 showable.h 8: Declaration missing ;
  Error E2141 showable.h 12: Declaration syntax error
  Error E2303 point.h 12: Type name expected
  Error E2139 point.h 12: Declaration missing ;
  Error E2061 point.h 17: Friends must be functions or classes
  Error E2139 point.h 17: Declaration missing ;
  Error E2321 point.h 18: Declaration does not specify a tag or an identifier
  
  Error E2303 shape.h 13: Type name expected
  Error E2139 shape.h 13: Declaration missing ;
  Error E2015 shape.cpp 16: Ambiguity between 'ostream' and 'std::ostream'
  Error E2238 shape.cpp 16: Multiple declaration for 'ostream'
  Error E2344 showable.h 12: Earlier declaration of 'ostream'
  Error E2141 shape.cpp 16: Declaration syntax error
  *** 15 errors in Compile ***
  showable.cpp:
  Error E2462 showable.h 8: 'virtual' can only be used with non-template memb
  er functions
  Error E2303 showable.h 8: Type name expected
  Error E2139 showable.h 8: Declaration missing ;
  Error E2141 showable.h 12: Declaration syntax error
  Error E2015 showable.cpp 7: Ambiguity between 'ostream' and 'std::ostream'
  Error E2238 showable.cpp 7: Multiple declaration for 'ostream'
  Error E2344 showable.h 12: Earlier declaration of 'ostream'
  Error E2141 showable.cpp 7: Declaration syntax error
  *** 8 errors in Compile ***
  </code></pre>