void myfun(CPoint *pts)
{
pts = new CPoint[2];
pts[0].x = 1;
pts[0].y = 1;
pts[1].x = 2;
pts[1].y = 2;
}CPoint *A = NULL;
myfun(A);
怎么A 没有值?急,请知道的说一下,谢谢
{
pts = new CPoint[2];
pts[0].x = 1;
pts[0].y = 1;
pts[1].x = 2;
pts[1].y = 2;
}CPoint *A = NULL;
myfun(A);
怎么A 没有值?急,请知道的说一下,谢谢
void myfun()
{
CPoint *pts = new CPoint[2];
pts[0].x = 1;
pts[0].y = 1;
pts[1].x = 2;
pts[1].y = 2;
return pts;
}
2、看看A[0],A[1]的值;
3、对结构和类对象尽量用引用(&)来返回。
void myfun(CPoint *pts)
这里是把指针所指的内容传进去了。
但指针本身没有传进去啊。
{
*pts = new CPoint[2];
CPoint *p = pts;
p[0].x = 1;
p[0].y = 1;
p[1].x = 2;
p[1].y = 2;
}这才是正确的。
我想返回一个int型,表示数组的个数?抄到这上面失误。
int myfun(CPoint *pts)
{
pts = new CPoint[2];
pts[0].x = 1;
pts[0].y = 1;
pts[1].x = 2;
pts[1].y = 2;
return 2;
}CPoint *A = NULL;
int icnt = myfun(A);//这里举例是写了两个点,实际中是很多的
CRgn rgn;
rgn.CreatePolygonRgn(A,icnt,ALTERNATE);这时看A中是空的。to: syy64(太平洋)
我是跟踪,执行完方法到
rgn.CreatePolygonRgn(A,icnt,ALTERNATE);这时看A中是空的。
我试试
加个引用
我应该怎么调用 呢
{
*pts = new CPoint[2];
CPoint *p = pts;
p[0].x = 1;
p[0].y = 1;
p[1].x = 2;
p[1].y = 2;
return 2;
}CPoint *A = NULL;
int i = myfun(A);
{
*pts = new CPoint[2];
CPoint *p = *pts;
p[0].x = 1;
p[0].y = 1;
p[1].x = 2;
p[1].y = 2;
}CPoint *A = NULL;
myfun(&A);
可以了.谢谢
这个语句是不是应该在函数的外面,由调用这个函数的函数来执行呢
{
pts = new CPoint[2];
pts[0].x = 1;
pts[0].y = 1;
pts[1].x = 2;
pts[1].y = 2;
}
CPoint *A = NULL;
myfun(A);
{
pts.SetSize(2);
pts[0].x = 1;
pts[0].y = 1;
pts[1].x = 2;
pts[1].y = 2;
return 2;
}CPointArray A;
int icnt = myfun(A);//这里举例是写了两个点,实际中是很多的
CRgn rgn;
rgn.CreatePolygonRgn(A[0],icnt,ALTERNATE);这时看A中是空的。
任何的参数的这种传递都是传一个副本进去。所以我们要改变什么值就要把它的地址传进去。
方法2:参数传递改为多加一个地址传参(**)