After researching this on the internet, I've been unable to get the Eclipse indexer to resolve "shared_ptr" from the C++0x additions that come with GCC 4.4.4. I made sure to create my project with the proper includes for Eclipse, so it's definitely looking in the the 4.4.4 include folders.
The program compiles and runs just fine. To access shared_ptr I'm using "#include <memory>".
Any idea what's breaking the indexer?
All the instances point to the same object, and share access to one "control block" that increments and decrements the reference count whenever a new shared_ptr is added, goes out of scope, or is reset. When the reference count reaches zero, the control block deletes the memory resource and itself.
std::shared_ptr. std::shared_ptr is a smart pointer that retains shared ownership of an object through a pointer. Several shared_ptr objects may own the same object.
shared_ptr is a smart pointer which can share the ownership of object (managed object). 1. Several shared_ptr can point to the same object (managed object). 2. It keep a reference count to maintain how many shared_ptr are pointing to the same object.
So the best way to return a shared_ptr is to simply return by value: shared_ptr<T> Foo() { return shared_ptr<T>(/* acquire something */); }; This is a dead-obvious RVO opportunity for modern C++ compilers. I know for a fact that Visual C++ compilers implement RVO even when all optimizations are turned off.
You need to set the pre-processor symbol '__GXX_EXPERIMENTAL_CXX0X__' to the eclipse project. g++ automatically adds that when you use '-std=c++0x', but eclipse is not aware of that, so it treats those sections of the relevant headers as disabled.
I experienced this problem under Windows with Eclipse 4.5.1 (Mars.1) and Cygwin 2.3.0 (GCC 4.9.3).
The indexer can't find shared_ptr because of lines like this in the <memory> header. The __cplusplus macro is evaluating to something other than C++ 11 (aka 201103) so the older auto_ptr.h is being included instead of shared_ptr.h. Why? The below screen shot of the project properties shows that C++ 98 (199711) is being detected under CDT GCC Build-in Compiler Settings.
#if __cplusplus >= 201103L # include <bits/shared_ptr.h> #else # include <backward/auto_ptr.h> #endif
There are two possible solutions to tell Eclipse to use C++ :
On the same Preprocessor Include Paths screen, scroll to the top of the Setting Entries area. Expand CDT User Setting Entries. Add a new Preprocessor Macro for __cplusplus=201103L. Do this for both the Release and Debug Configurations. Then rebuild the index.
If you want to default the CDT GCC Build-in Compiler Settings to use 201103 for all projects, then edit the language.settings.xml file (under Windows this is c:\Users\deanhill\workspace\.metadata\.plugins\org.eclipse.cdt.core\language.settings.xml). Set __cplusplus=201103L. Restart Eclipse and rebuild the index.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With