呼び出しタイミング
#include <iostream>
using namespace std;
class Integer
{
private:
int i;
public:
Integer(int i=0) { this->i = i; };
Integer(const Integer& obj) {
cout << "Copy" << endl;
i = obj.i;
}
Integer& operator=(const Integer& obj) {
cout << "Substitute" << endl;
i = obj.i;
return *this;
}
};
int main()
{
cout << "(1)" << endl;
Integer a(10), b;
cout << "(2)" << endl;
b = a;
cout << "(3)" << endl;
Integer c = a;
cout << "(4)" << endl;
return 0;
}
(1)
(2)
Substitute
(3)
Copy
(4)
当然といえば当然なんですが、main関数の4行目は代入です。
そして、6行目は初期化です。
授業のスライドで間違ってたような気がしたから、一応言っておいたけど、返信されるのはいつになることやら。
代入って英語でsubstituteであってたっけ?