[英]How to define a type conversion from std::string to a custom type?
Conversion operators are declared inside a class like this: 转换运算符在这样的类中声明:
operator string();
When declared, they can be defined like this; 声明时,可以这样定义:
Foo::operator string(){ return stringRep; }
How can I define a conversion operator from string to my custom type? 如何定义从字符串到我的自定义类型的转换运算符?
编写一个接受字符串的构造函数。
A conversion operator/function operator Tc
, of a Class of type Ty is a non static member function which converts the Type Ty to some specified type. Ty类型的转换操作符/函数
operator Tc
是一个非静态成员函数,它将Ty类型转换为某些指定类型。
If you need to convert from string, which is a Class of type std::basic_string<char>
to a Type of Tc
, either 如果需要从字符串(
std::basic_string<char>
类型的类型)转换为Tc
的类型,则可以
std::basic_string
, needs to provide a Type conversion function, or std::basic_string
,需要提供类型转换功能,或者 std::basic_string<char>
. std::basic_string<char>
类型的对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.