实验5 类和对象实验报告(3)

发布时间:2021-06-06

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;}

实验5 类和对象实验报告(3).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219