3)error C2512: 'Coordinate' : no appropriate default constructor available
error C2664: '__thiscall Coordinate::Coordinate(class Coordinate &)' : cannot convert parameter 1 from 'const int' to 'class Coordinate &'
A reference that is not to 'const' cannot be bound to a non-lvalue
修改:
#include <iostream>
using namespace std;
class Coordinate
{
public:
Coordinate(int x1, int y1){x=x1; y=y1;} Coordinate(Coordinate &p);
Coordinate();
Coordinate(int i);
~Coordinate(){cout<<"Destructor is called."<<endl;} int getx(){return x;} int gety(){return y;}
private:
};
Coordinate::Coordinate(Coordinate &p){
}
int main(){
Coordinate p1(3,4); Coordinate p2(p1); x=p.x; y=p.y; cout<<"Copy initianization constructor is called."<<endl; int x, y;
Coordinate p5(2);
Coordinate p3=p2; cout<<"p3=("<<p3.getx()<<","<<p3.gety()<<")"<<endl;
return 0;}