是否可以在第三方库类型之间定义隐式或显式转换?

时间:2018-01-11 14:45:26

标签: c++ qt

我正在使用Qt以及其他库。 Qt使用QString代替std::string。当我想使用不是Qt的库时,函数会请求std::string,因此,每次我必须调用非Qt库时,我必须使用转换QString::toUtf8().constData()。有没有办法让我可以编写显式或隐式转换(我不知道应该是哪一个)让我在QString的位置使用std::string

一个例子就像是

void func(std::string in)
{
    std::cout<<in<<std::endl;
}

然后将其用作:

QString s("this is the message");
func(s);

而不是

QString s("this is the message");
func(s.toUtf8().constData());

我无法提供任何我尝试过的例子,因为我只找到了conversions来定制的类。

谢谢。

0 个答案:

没有答案