如何打印指向函数 print 中类类型的指针的值作为我尝试的地球,但我想知道如何打印指针指向的 x 和 y 的值。这段代码:
int main(){
#include<iostream>
using namespace std;
class POINT {
public:
POINT (){ }
POINT (int x, int y){ x_=x; y_=y;}
int getX (){ return x_; }
int getY (){ return y_; }
void setX (int x) { x_ = x; }
void setY (int y) { y_ = y; }
void print( ) { cout << "(" << x_ << ","<< y_ << ")";}
void read( ) {cin>> x_; cin>>y_;}
private:
int x_;
int y_;
};
void print ( POINT * p1Ptr , POINT * p2ptr){
POINT* x= p1Ptr; POINT*y=p2ptr;
cout<<x<<y;
}
int main(){
POINT p1(3,2);
POINT p2(6,6);
POINT *p1Ptr=&p1;
POINT *p2Ptr=&p2;
double d=0.0;
double *dPtr=&d;
p1Ptr->getX();
p2Ptr->getX();
p1Ptr->getY();
p2Ptr->getY();
print ( &p1, &p2);
system ("pause");
return 0;
}