string("abc") 是否返回任何内容? [英] Does string("abc") return anything?
本文介绍了string("abc") 是否返回任何内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
像这样:
#include <iostream>
using namespace std;
int main()
{
if ( string( "abc" ).size() == 3 )
cout << "equ." << endl;
return 0;
}
string("abc")
是否返回任何内容?如果是,那是值还是引用?
Does string("abc")
return anything? If it does, that's a value or a reference?
推荐答案
类构造函数没有指定返回类型,也没有 return 语句.但是它们确实具有隐式返回类型 - 与声明它们的类相同,并且构造函数返回"刚刚构造的对象.
Class constructors do not have specified return type, and do not have return statement. But they do have implicit return type - same as class in which they are declared and constructor "returns" just constructed object.
T()
调用默认构造函数并返回"类型为 T
的匿名 prvalue
(绑定到 T&&
).它的生命周期是使用它的表达式的生命周期.它是可修改的.
T()
calls default constructor and "returns" anonymous prvalue
of type T
(which binds to T&&
). Its lifetime is lifetime of expression in which it is used. It is modifiable.
使用示例:
int() // 0
(string()+=string("123")+="abc").substr(1,3) // "23a"
这篇关于string("abc") 是否返回任何内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文