用户仅能修改Int.h中的内容。
注意:除了提供拷贝构造函数意外,还需提供默认构造函数。
main.cpp的内容如下:
#include "Int.h"
#include <iostream>
using namespace std;
int main(){
int x;
cin>>x;
Int a;
a.setValue(x);
Int b(a);
cout<<b.getValue()<<endl;
return 0;
}
#ifndef _INT_H_
#define _INT_H_
class Int{
private:
int value;
public:
//请在以下空白书写拷贝构造函数,即以本类的常引用为参数的构造函数
Int(){}
Int(Int const &a):value(a.value){}
int getValue()const{return value;}
void setValue(int v){value=v;}
};
#endif
#####答案是抄的,我不是很懂,看了一些资料,但是好像没有解释的很清楚,可以具体说说吗
拷贝构造我理解的形式是class名(class名 const &p){};
不是很懂哎