当我使用“将定义添加到xxx.cpp”时,为什么Qt Creator使用std :: ___ LIBCPP_ABI_VERSION :: string而不是std :: string?这是什么意思?

当我定义一个方法接受std::string头文件并Add Definition to xxx.cpp在Qt Creator中使用“ ”功能时,它将在.cpp中创建一个定义,其中所有std :: string参数都使用type std::___LIBCPP_ABI_VERSION::string

通常我只是删除“ ___LIBCPP_ABI_VERSION::”,但这是什么意思?为什么会发生这种情况?如何让qt创建者按预期方式简单地使用std :: string?

这是在OSX中。我应该在我的.pro文件中添加以下内容:

LIBS += -stdlib=libc++
LIBS += -lstdc++

为了使用C ++ 11。我猜想这与标准库的使用有关,但我不知道到底是什么问题。

西蒙·沃塔

这是因为您可以“重定向”类型,并且Qt Creator以不同的方式解决此重定向问题,也许并不总是以最需要的方式进行。

假设FooinNamespace1Barin有2种类型Namespace2现在,您可以创建Bar一种类型,Namespace1以便能够通过访问它Namespace1::Bar

bar.h

#pragma once

namespace Namespace2 {

struct Bar
{
};

}

foo.h

#pragma once

#include "bar.h"

namespace Namespace1
{
    using MyBar = Namespace2::Bar; // i.e. Namespace1::MyBar
    using Namespace2::Bar;         // i.e. Namespace1::Bar

    class Foo
    {
    public:
        Foo(const Bar &bar);
        Foo(const MyBar &bar);
    };
}

在foo标头中,两个参数均为类型,Namespace1但它们以不同的方式重定向(请参见using语句)。对于编译器来说都是一样的,但是Qt Creator将类型扩展到cpp文件中的方式有所不同

foo.cpp

#include "foo.h"

namespace Namespace1 {

Foo::Foo(const Namespace2::Bar &bar)
{
}

Foo::Foo(const MyBar &bar)
{
}

}

在OS X上的C ++标准库中,std::string不是直接实现而是将std::___LIBCPP_ABI_VERSION::string重定向到,然后实现该功能。对于您来说,这根本是不可见的,因为它是实现的详细信息,将来可能会更改。你一直在努力std::string您可以并且始终应该用标头中使用的原始类型替换类型。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档