代码之家  ›  专栏  ›  技术社区  ›  MaPo

C++构造函数与rValk

  •  0
  • MaPo  · 技术社区  · 7 年前

    this post .注意的代码如下

    struct S {
      void func() &;
      void func() &&;
    };
    
    S s1;
    s1.func(); // OK, calls S::func() &
    S().func(); // OK, calls S::func() &&
    

    S()

    2 回复  |  直到 7 年前
        1
  •  3
  •   StoryTeller - Unslander Monica    7 年前

        2
  •  2
  •   navyblue    7 年前

    S() 创建一个临时对象,该对象是右值。对象是使用默认构造函数构造的。它将在计算完整表达式后销毁。

    S