0

问题可能是微不足道的,但我还没有找到任何相关的答案。我的示例代码:

#include <iostream>

struct ExampleStruct {
  int a;
  std::string b;
  double c;
};

ExampleStruct&& getExampleStruct() {
  ExampleStruct obj;
  obj.a = 1;
  obj.b = std::string("asdf");
  obj.c = 1.43;

  return std::move(obj);
}

int _tmain(int argc, _TCHAR* argv[]) {
  ExampleStruct&& moved_obj = getExampleStruct();

  // moved_obj.a == 1
  // moved_obj.b == ""
  // moved_obj.c == 1.43

  return 0;
}

为什么被moved_obj.b清空,而moved_obj.amoved_obj.c保持不变?

4

0 回答 0