Re: PolyLine
"Luigino" <npuleio@rocketmail.com> ha scritto nel messaggio
news:c8fc0f52-bd2c-423e-90fe-f97568d74098@m38g2000yqd.googlegroups.com...
(dc.)BOOL CDC::Polyline(const POINT * lpPoints, int nCount);
Actually I implemented like this:
dc.Polyline(reinterpret_cast<POINT*> (&singlepoints), singlepoints.size
())
If 'singlepoints' is an instance of a std::vector<POINT> (as you wrote in a
previous post), the reinterpret_cast is unnecessary and wrong.
&singlepoints is the address of an instance of std::vector, which is wrong
in your above context.
Instead, you need a pointer to the first element of the vector, i.e.
&singlepoints[0] (assuming the vector is not empty).
In fact, the first argument of CDC::Polyline is a 'const POINT *'.
I repeat:
dc.Polyline( &singlepoints[0], singlepoints.size() );
is just fine.
Please read my previous post.
You can also verify with the following C++ FAQ:
http://www.parashift.com/c++-faq-lite/containers.html#faq-34.3
I verified also with a simple code snippet:
Create a MFC doc/view project with MFC app wizard, and paste this code in
the view class OnDraw() method:
<code>
typedef std::vector<POINT> Points;
Points points;
const int N = 5;
POINT pt;
int x1 = 10;
int x2 = 30;
int dx = (x2 - x1)/N;
int x = x1;
for (int i = 0; i < N; i++)
{
pt.x = x;
pt.y = 2*x;
points.push_back(pt);
x += dx;
}
pDC->Polyline( &points[0], points.size() );
</code>
Assuming that you add '#include <vector>' in "StdAfx.h", the above code
compiles fine and seems to me to run fine.
Giovanni