在 C++ 中,我正在尝试使用点类创建一个三角形类。java中的正确方法是:
public class Point {
double x, y;
public Point(double x, double y){
this.x=x;
this.y=y;
}
}
public class Triangle {
Point p1,p2,p3;
public Triangle(Point p1, Point p2, Point p3){
this.p1=p1;
this.p2=p2;
this.p3=p3;
}
}
主要:
Point p1=new Point(0,0);
Point p2=new Point(1,1);
Point p3=new Point(-1,1);
Triangle t1=new Trianle(p1,p2,p3);
在 C++ 中我有:
class point{
double x1,y1;
public:
point(double x, double y){
x1=x;
y1=y;
}
};
class triangle{
point p1, p2, p3;
public:
triangle(point varp1, point varp2, point varp3){
p1=varp1;
p2=varp2;
p3=varp3;
}
};
主要:
point p1(-1,1);
point p2(1,1);
point p3(0,0);
triangle t1(p1,p2,p3);
不知何故,这不起作用,为什么?..................................................... ..................................................... ..................................................... ..................................................... ………………………………………………………………………………………………………………………………………………