【发布时间】:2019-06-29 17:10:11
【问题描述】:
我有这个小的 c++ 代码 sn-p,有人可以解释一下 operator= 是如何工作的吗?
#include <iostream>
#include <string>
using namespace std;
static wstring & test() {
static wstring test2;
return test2;
};
int main()
{
test() = L"Then!";
wcerr << test() << endl;
}
【问题讨论】:
-
我不明白你的实际问题是什么。
=运算符将一件事分配给另一件事。这有多令人困惑? -
这似乎是您关于 references 如何在 C++ 中工作的真实问题;不是赋值。
标签: c++ operator-overloading operators