Yeah, might want to create your own more useful point class then.
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
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; }
Woop?
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.
Woop?
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.