返回引用不是return &返回值,而是

类似:

std::vector<int>& test()

{

  ....

  //m_a是成员变量

   return m_a;

}

那么改变能直接作用到成员变量,如果不是std::vector<int>& 而是std::vector<int>,那么就不能直接作用到m_a。虽然这种方法破坏封装,但是可以达到目的。

 

相关文章:

  • 2022-12-23
  • 2022-01-07
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
猜你喜欢
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2021-04-10
  • 2021-08-16
相关资源
相似解决方案