虽然复制构造函数和赋值运算符都执行相同的复制工作,但为什么一个任务需要两种不同的方法。是由于不同的写入方式导致执行不同的操作吗?即,分数a = b将调用副本构造函数,而b = a在声明分数b之后将调用赋值运算符。
#include <iostream>
class fraction{
// some code
};
int main(){
fraction a;
fraction b = a; // invokes the copy constructor
b = a; // will invoke the assignment operator
}