引用“http://www.cnblogs.com/Mr-xu/archive/2012/08/07/2626973.html”

void
CMainWindow::showMsg(QString &text)
那么,showMsg("test");  // 错误

voidCMainWindow::showMsg(const QString &text)
那么,showMsg("test");  // 正确

【例4】:假设有如下函数声明:
string foo( );
void bar(string & s);
  那么下面的表达式将是非法的:
bar(foo( ));
bar("hello world");
  原因在于foo( )和"hello world"串都会产生一个临时对象,而在C++中,这些临时对象都是const类型的。因此上面的表达式就是试图将一个const类型的对象转换为非const类型,这是非法的。

相关文章:

  • 2021-12-30
  • 2022-12-23
  • 2022-02-04
  • 2021-10-08
  • 2021-09-29
  • 2021-11-07
猜你喜欢
  • 2021-12-21
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
相关资源
相似解决方案