运算符std :: string()const? [英] operator std::string() const?

查看:431
本文介绍了运算符std :: string()const?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我究竟是什么

Can somebody tell me what precisely

operator std::string()

代表?

推荐答案

转换运算符,允许对象显式或隐式转换为std ::串。当这样的转换发生时,调用操作符并且转换的结果是调用的结果。

It is a conversion operator that allows the object to be explicitly or implicitly casted to std::string. When such a cast occurs, the operator is invoked and the result of the cast is the result of the invocation.

作为隐式转换的示例,假设你有一个函数接受类型 std :: string const std :: string& ,但不是给定的对象类型。将对象传递给该函数将导致转换操作符被调用,结果传递到函数而不是你的类型。

As an example of an implicit cast, suppose you had a function that accepted type std::string or const std::string&, but not the given object type. Passing your object to that function would result in the conversion operator being invoked, with the result passed to the function instead of your type.

这篇关于运算符std :: string()const?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆