开发者

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

开发者 https://www.devze.com 2023-03-11 11:45 出处:网络
I am trying 开发者_运维技巧to get up to speed with using shared_ptr, but I can\'t seem to figure out why the following code wont compile.

I am trying 开发者_运维技巧to get up to speed with using shared_ptr, but I can't seem to figure out why the following code wont compile.

In the header file, private member declaration:

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

In the constructor, trying to instantiate an object of the above:

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

The error message:

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

I'd like to convert my pointers step by step, but I can't seem to figure out why the above shoots an error. Can anyone advise? Thanks!

EDIT:

I found out why. I had 2 vim instances open, and one was writing to a temporary swap file and not actually looking at the changes when compiling. Thanks for the input guys.


You cannot have posted your code verbatim.

Your header must say std::map<std::string, std::vector<int> > *_myMap;

Are you sure you're building properly? Try a fresh build.


Are you sure that is the current definition? The error says your map is declared in the header as

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

精彩评论

暂无评论...
验证码 换一张
取 消