C ++オブジェクト指向プログラミング010:返されるもの----(北京大学Mooc)

記事のディレクトリ


元のタイトル

ここに画像の説明を挿入します

#include <iostream>
using namespace std;
class A {
    
    
public:
	int val;

	A(int
// 在此处补充你的代码
};
int main()
{
    
    
	int m,n;
	A a;
	cout << a.val << endl;
	while(cin >> m >> n) {
    
    
		a.GetObj() = m;
		cout << a.val << endl;
		a.GetObj() = A(n);
		cout << a.val<< endl;
	}
	return 0;
}


コード

	A(){
    
    val = 123;}
    A(int n)
    {
    
    
        val = n;
    }
    A& GetObj()
    {
    
    
        return *this;//去查阅了答案才知道有这个指针
    }

おすすめ

転載: blog.csdn.net/qq_37500516/article/details/114751902