繁体   English   中英

将CustomString&传递给构造函数不会从“字符串”隐式转换

[英]passing CustomString& into a constructor won't implicit convert from “string”

我可以得到编译器(msvc ++ express)在构造函数中将“字符串”转换为CustomString,但是没有引用。 因此,如果编译器认为可以的话,是否会有通过引用传递进行优化的机会,就像使用其他类型的值传递一样吗?

不会使用进行隐式转换

new xmlNode("string")

 xmlNode( CustomString& label )
 {
    this->text = label;
 }

将:

 xmlNode( CustomString label )
 {
    this->text = label;
 }

尝试:

xmlNode(const CustomString& label )
{
    this->text = label;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM