Hi,

I am getting below error after executing below code.

Error: In function main': undefined reference toPoint2D::Point2D(int, int)'

class Point2D
{
 public:
           Point2D(int,int);
           int getX();
           int getY();

           void setX(int);
           void setY(int);

           double getScalarValue();

    bool operator< (const Point2D &right) const
    {
      return x < right.x;
    }

     protected:

             int x;
             int y;
             double distFrOrigin;
             void setDistFrOrigin();


};


int main()
{
      Point2D abc(2,3);

   set<Point2D> P2D;
   P2D.insert(abc); // i am getting error here ,i dont know why
   return 1;
}

You're trying to use a constructor that doesn't exist Point2D(int,int);

I'd guess you meant to write something like:

Point2D::Point2D (int xVal, int yVal): x(xVal), y(yVal)
{}

Thanks for uncover this silly mistake. one more thing i would like to know , why i am not getting any error during insertion without implementing overloading operator '<' in polymorphic class Shape. in below code snippet Shape is a abstract class.Does it mean polymorphic class (interface specific only) comparison operator is not needed.

set<Shape*> ob;
Circle *ob1 = new Circle;

Square *ob2 = new Square;

ob.insert(ob1);// No error during insertion in the absence of operator 

ob.insert(ob2);//No error during insertion in the absence of operator

You are inserting pointers. Pointers have suitable comparison operators.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.