Yeah, might want to create your own more useful point class then.
Printable View
Yeah, might want to create your own more useful point class then.
Do you have any ideas of how to overcome this?
IF I made my own POINT class then that could work, using a constructor as the guy before suggested?
That's what I said... You could make a CPNT class, that is capable of returning a point (by default, perhaps). But it seems a bit unnecessary.
I'd probably make a small utility function:Then you can write something likeCode:void AddPoint(vector<POINT>& v, int x, int y)
{
POINT p;
p.x = x;
p.y = y;
v.push_back(p);
}
--Code:vector<POINT> square;
AddPoint(square, 0, 0);
AddPoint(square, 100, 0);
AddPoint(square, 100, 100);
AddPoint(square, 0, 100);
Mats
ahhh
brilliant :)
You could write a class that uses Point and also overloads the common operators used on points such as addition, subtraction, equality, assignment, etc.
Or even this ;)
Code:class CustomPoint
{
public:
CustomPoint(int x, int y)
{
mPoint.x = x;
mPoint.y = y;
}
operator POINT&()
{
return mPoint;
}
private:
POINT mPoint;
};
void FunctionThatExpectsPoint(POINT pt)
{
std::cout<<"x = "<<pt.x<<" y = "<<pt.y;
}
int main(void)
{
std::vector<CustomPoint> myPoints;
myPoints.push_back(CustomPoint(30, 20));
myPoints.push_back(CustomPoint(10, 50));
FunctionThatExpectsPoint(myPoints[0]);
std::cin.get();
return 0;
}
Personally, I'd leave it as a C struct. Unless you want certain operations as Bubba mentioned.
FYI, point is defined with "LONG" not "int" (note: not "long") . As per MSDN - http://msdn.microsoft.com/en-us/libr...19(VS.85).aspx
Agreed.
Just having some fun with overloaded operators.
I would derive from POINT and add specific features, since conversion operators can cause unexpected and unwanted implicit conversions.
The brilliance of deriving from the original POINT is that you can then pass it to any function requiring a POINT* or POINT& and it will behave exactly the same.
Not entirely sure if that's correct:
That will NOT work, because the pointer to the octagon contains 12 bytes per entry. Of course, nor will the CustomPoint method described above (at least not unless by chance).Code:class MYPOINT: PUBLIC POINT
{
public:
int a;
MYPOINT(LONG xx, LONG yy, int aa): x(xx), y(yy), a(aa)
{
}
}
...
void func()
{
MYPOINT *octagon = new MYPOINT[9];
...
Polygon(hdc, octagon, sizeof(octagon)/sizeof(octagon[0]));
...
}
--
Mats
Although now that you remind me, this opens a whole new can of worms, too.
Perhaps the best course of action is a legacy get() function that returns a POINT.
Then whether you derive from POINT or not is up to you.
Again, that will only work for individual POINT items - polygon takes an array [as a pointer], so you still need to have an array of them in some way.
Using a function like I described WORKS - it is not the C++ way to do it, but unfortunately, I don't think that can be achieved at this point in time - because the GDI functionality that does the actual drawing in a Windows GUI application doesn't support OBJECTS as the input.
--
Mats