采用不同数据类型的赋值操作符的名称是什么?

C++: What is the name of the assignment operator which takes different data type

本文关键字:是什么 赋值操作符 数据类型      更新时间:2023-10-16

我很困惑,记不起一个类的赋值运算符的名字,它接受的数据类型与当前类的const&不同…

:

struct Thing 
{
    Thing& operator = (const Thing& other); // This is Assignment Operator
    Thing& operator = (int xyz); // What is the name of this?
    // really not needed here, just to exemplify that this class has an int
    int memberStuff;
};

那么,问题是:Thing& operator = (int xyz);struct Thing的一个成员,它的名字是什么?是赋值运算符还是别的什么?

都是赋值。

唯一的问题是,第一个操作符(接受对同一类对象的引用)可以称为复制赋值操作符,而另一个操作符只是普通的赋值操作符。