下面的C++代码(关于shared_ptr)有什么问题

What is wrong with following C++ code (regarding shared_ptr)

本文关键字:ptr 问题 什么 shared 关于 C++ 代码      更新时间:2023-10-16

我正试图加快使用shared_ptr的速度,但我似乎不明白为什么以下代码无法编译。

在头文件中,私有成员声明:

std::map<std::string, str::tr1::shared_ptr< std::vector<int> > > *_myMap;

在构造函数中,尝试实例化上面的对象:

_myMap = new map<string, std::tr1::shared_ptr< vector<int> > >();

错误消息:

Test.cpp:14:68: error: cannot convert ‘std::map<std::basic_string<char>, std::tr1::shared_ptr<std::vector<int> > >*’ to ‘std::map<std::basic_string<char>, std::vector<int> >*’ in assignment

我想一步一步地转换我的指针,但我似乎不明白上面为什么会出错。有人能提出建议吗?谢谢

编辑:

我发现了原因。我打开了两个vim实例,其中一个正在写入一个临时交换文件,而在编译时并没有真正查看更改。谢谢你们的投入。

您不可能逐字逐句地发布代码。

您的标题必须显示std::map<std::string, std::vector<int> > *_myMap;

你确定你的建筑是否正常?尝试全新构建。

您确定这是当前的定义吗?错误显示您的地图在标题中声明为

std::map<std::string, std::vector<int> >*