error C2679: binary '!=' : no operator found which takes a right-hand operand of type 'int' In VS2008
-
Hi, dear all, I create a class name Point2D to store coordinate value, with "<" and "==" two operators overloadings. Then create a type based on it as: typedef std::vector<Point2D*> Point2D_Vector; Point2D_Vector PointVector; Then add some data to PointVector. When I loop the vector: Point2D_Vector::iterator itr; for (itr=PointVector.begin(); itr!=PointVector.end(); itr++) if (itr != 0) delete *itr; They work fine in C++6.0, now when I try to compile it in VS2008 I got the error message in if(itr != 0) line: error C2679: binary '!=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion) How can I solve this issue? Thanks!
-
Hi, dear all, I create a class name Point2D to store coordinate value, with "<" and "==" two operators overloadings. Then create a type based on it as: typedef std::vector<Point2D*> Point2D_Vector; Point2D_Vector PointVector; Then add some data to PointVector. When I loop the vector: Point2D_Vector::iterator itr; for (itr=PointVector.begin(); itr!=PointVector.end(); itr++) if (itr != 0) delete *itr; They work fine in C++6.0, now when I try to compile it in VS2008 I got the error message in if(itr != 0) line: error C2679: binary '!=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion) How can I solve this issue? Thanks!
The statement
itr != 0
makes no sense. Even when it compiled in VC6 it wasn't doing what it looks like you intended (to stop deleting a NULL pointer). You probably mean this:if (*itr != 0)
Also, deleting a NULL pointer is safe in C++ (it does nothing). The check is not needed and it potentially makes the code less efficient as the compiler inserts code to check for this automatically.
Steve
-
Hi, dear all, I create a class name Point2D to store coordinate value, with "<" and "==" two operators overloadings. Then create a type based on it as: typedef std::vector<Point2D*> Point2D_Vector; Point2D_Vector PointVector; Then add some data to PointVector. When I loop the vector: Point2D_Vector::iterator itr; for (itr=PointVector.begin(); itr!=PointVector.end(); itr++) if (itr != 0) delete *itr; They work fine in C++6.0, now when I try to compile it in VS2008 I got the error message in if(itr != 0) line: error C2679: binary '!=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion) How can I solve this issue? Thanks!
if ((*itr)!=0)
-
The statement
itr != 0
makes no sense. Even when it compiled in VC6 it wasn't doing what it looks like you intended (to stop deleting a NULL pointer). You probably mean this:if (*itr != 0)
Also, deleting a NULL pointer is safe in C++ (it does nothing). The check is not needed and it potentially makes the code less efficient as the compiler inserts code to check for this automatically.
Steve