1

I am a beginner in C++. I have this header file called SharedData.h. Its given below.

//SharedData.h

#include <memory>

typedef struct Shared_data
{
    std::string _data;
    bool IsConsumedbyNodeA;
    bool IsConsumedbyNodeB;

public:
    Shared_data():
        tokenizer_data(""),IsConsumedbyNodeA(false),IsConsumedbyNodeB(false){};
    Shared_data& ReadSharedData();
    void WriteSharedData(Shared_data &);
}Shared_data;

extern std::shared_ptr<Shared_data> ptr_to_Shared_data;//I am getting the above mentioned error here

The shared_ptr is being defined in Shared_data.cpp so that I get single copy of the object in memory and extern declaration wherever I include the header.

I tried a lot but don't know how to resolve this error.

Please Help.....

Regards, TechTotie

TechTotie
  • 127
  • 1
  • 15

2 Answers2

0

You need to include the header memory.

pmr
  • 58,701
  • 10
  • 113
  • 156
  • I have already included header file #include Just forgot to mention it here.Sorry for that. – TechTotie Feb 18 '14 at 06:56
  • @TechTotie Have you told your compiler to use C++11 mode? For `clang` and `gcc` you need to add the flag `-std=c++11`. Failing this, have you checked your compiler actually supports C++11? `gcc --version` should be at least 4.8 and `clang --version` at least 3.4. – pmr Feb 18 '14 at 09:37
  • Thanks for your help. I am using mingw32 for compilation. I think it does support C++ 11. But still I will give a try using -std=c++11 flag and I will also check the gcc version. – TechTotie Feb 18 '14 at 10:37
  • I checked the version in MingW with "gcc --version" it is "gcc.exe (GCC) 4.8.1". Does it support C++11? and I tried with -std=c++11 but it did not work.It's giving "cc1plus.exe: error: unrecognized command line option "-std=c++11"". – TechTotie Feb 18 '14 at 17:42
  • @TechTotie Yes, it should. You shouldn't pass those commands directly to `cc1plus` but to `g++`. Unfortunately I'm not familiar with MinGW and can't help you with this. – pmr Feb 18 '14 at 17:52
0

For use std::shared_ptr you should enable support for C++11 standard and include header memory.

ForEveR
  • 55,233
  • 2
  • 119
  • 133