求各位路過的大神看看:代碼如下:
在Tri類成員函式中用cout<<pos2.q[j]<<endl;這句輸出不到正確的結果,輸出是負值。該怎么解決?
#include<iostream.h>
#include<math.h>
class Tri;
class Point
{
private:
int x,y;
public:
int q[3];
Point(int c[])
{
q[0]=c[0];
q[1]=c[1];
q[2]=c[2];
cout<<"shuzu:"<<q[1]<<endl;
}
Point(int xx=0,int yy=0)
{
x=xx; y=yy;
}
friend class Tri;
};
class Tri
{
private:
Point pos1,pos2,pos3;
public:
Tri(Point px1,Point px2,Point px3)
{pos1=px1;pos2=px2;pos3=px3;}
double Area();
};
double Tri::Area()
{
cout<<pos2.x<<endl;
for(int j=0;j<3;j++)
cout<<pos2.q[j]<<endl;
return 0;
}
void main()
{
int b[3]={1,2,3};
Point niu(b);
Point pt1(1,1),pt2(7,1),pt3(4,5);
Tri tria(pt1,pt2,pt3);
tria.Area();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/60150.html
