私はC++プログラミングの新人です。両方のメンバーが同じ価値観を示す部分にはまっています。なぜか説明できますか?あらかじめThx。コピーコンストラクタは実際に何をしますか?
#include<iostream>
using namespace std;
class test{
public:
int all,sum;
test(int x){
all=x;
}
test(test &a){
all=a.all+5;
cout<<all;
}
void one(test m){
cout<<endl;
cout<<endl<<m.all;
cout<<endl<<all;
}
};
int main(){
test a(10),b(a);
b.one(a);
return 0;
}
。また、複数の変数ではなく、1行に1つの宣言/初期化のみを提案します。 – CoryKramer
コピーコンストラクタは、あなたがやりたいことを何でもすることができます。通常、メンバは別のオブジェクトから* this *オブジェクトにコピーされます。 –
A *デバッガ*を使用すると、StackOverflowに投稿して回答を待つよりも速くこの質問に答えることができます。 –