# Thread: Vectors and Windows Programming

1. Yeah, might want to create your own more useful point class then.

2. 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?

3. Originally Posted by strokebow
Nice thought. But,

error C2661: 'tagPOINT::tagPOINT' : no overloaded function takes 2 arguments
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:
Code:
```void AddPoint(vector<POINT>& v, int x, int y)
{
POINT p;
p.x = x;
p.y = y;
v.push_back(p);
}```
Then you can write something like
Code:
```    vector<POINT> square;
--
Mats

4. ahhh
brilliant

5. You could write a class that uses Point and also overloads the common operators used on points such as addition, subtraction, equality, assignment, etc.

6. 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;
}```

7. 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

8. Agreed.

Just having some fun with overloaded operators.

9. 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.

10. Originally Posted by Elysia
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:
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]));
...
}```
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).

--
Mats

11. 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.

12. Originally Posted by Elysia
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