J
jut_bit_zx
Consider the following code:
#include <iostream>
#include <map>
using namespace std;
typedef struct tagPOINT
{
tagPOINT();
bool operator == (const tagPOINT& point);
bool operator < (const tagPOINT& point);
unsigned int x;
unsigned int y;
} POINT;
class less_point
{
public:
bool operator()(const tagPOINT& point1,const tagPOINT& point2)
{
return (point1.y < point2.y);
}
};
tagPOINT::tagPOINT()
{
x = 0;
y = 0;
}
bool tagPOINT:perator == (const tagPOINT& point)
{
if((x == point.x) && (y == point.y))
{
return 1;
}
return 0;
}
bool tagPOINT:perator < (const tagPOINT& point)
{
return (y < point.y);
}
typedef map<POINT, int>::value_type pixelValue;
typedef map<POINT, int, less_point> pointmap;
int main(int argc, char* argv[])
{
pointmap pixelArray;
POINT point;
pixelArray.insert(pixelValue(point, 1));
cout<<pixelArray[point]<<endl;
return 0;
}
Q: The compile environment is Microsoft VC6.0, and the compile erros
are:"cannot convert 'this' pointer from 'const class less_point' to
'class less_point &' Conversion loses qualifiers" . what's wrong with
the code?
Thanks!
#include <iostream>
#include <map>
using namespace std;
typedef struct tagPOINT
{
tagPOINT();
bool operator == (const tagPOINT& point);
bool operator < (const tagPOINT& point);
unsigned int x;
unsigned int y;
} POINT;
class less_point
{
public:
bool operator()(const tagPOINT& point1,const tagPOINT& point2)
{
return (point1.y < point2.y);
}
};
tagPOINT::tagPOINT()
{
x = 0;
y = 0;
}
bool tagPOINT:perator == (const tagPOINT& point)
{
if((x == point.x) && (y == point.y))
{
return 1;
}
return 0;
}
bool tagPOINT:perator < (const tagPOINT& point)
{
return (y < point.y);
}
typedef map<POINT, int>::value_type pixelValue;
typedef map<POINT, int, less_point> pointmap;
int main(int argc, char* argv[])
{
pointmap pixelArray;
POINT point;
pixelArray.insert(pixelValue(point, 1));
cout<<pixelArray[point]<<endl;
return 0;
}
Q: The compile environment is Microsoft VC6.0, and the compile erros
are:"cannot convert 'this' pointer from 'const class less_point' to
'class less_point &' Conversion loses qualifiers" . what's wrong with
the code?
Thanks!