0

Regarding the use of shared_pointers in a c++ program, I have declared the #include <memory> and then called upon the following std::shared_ptr<int>(new int(5)) it refuses to compile saying that

error: 'shared_ptr' is not a member of 'std'

or alternatively

Symbol 'shared_ptr' could not be resolved

Can anyone tell me why this is happening? from what i read, shared point should be defined in std or boost libraries and i have tried them both

1 Answers1

4

std::shared is a C++11 feature.

You must have a compiler supporting this.

For example with GCC you should add -std=c++11 or -std=gnu++11.

If you don't have C++11, you can also use boost::shared_ptr.

Pierre Fourgeaud
  • 14,290
  • 1
  • 38
  • 62
  • I tried doing that - doesn't work with the error "Symbol 'shared_ptr' could not be resolved " – Noam Fisher Sep 20 '13 at 11:17
  • @NoamFisher What is your compiler? [**example**](http://ideone.com/e7ekSm) with gcc v4.8.1. – Pierre Fourgeaud Sep 20 '13 at 11:24
  • thanks for the help. This was the question I as looking for. also had to update the CDT. http://stackoverflow.com/questions/8312854/eclipse-indexer-cant-resolve-shared-ptr – Noam Fisher Sep 20 '13 at 12:14