I'm trying to compile code w/ shared_ptrs on Raspberry Pi:
#include <iostream>
using namespace std;
int main(int argc, char* argv[]){
shared_ptr<string> message1(new string("Hello Raspberry Pi C++11"));
cout << *message1 <<endl;
return 0;
}
I get the following error:
test.cpp: In function 'int main(int, char**)': test.cpp:4:4: error: 'shared_ptr' was not declared in this scope
shared_ptr<string> message1(new string("Hello Raspberry Pi C++11"));
^ test.cpp:4:21: error: expected primary-expression before '>' token
shared_ptr<string> message1(new string("Hello Raspberry Pi C++11"));
^ test.cpp:4:70: error: 'message1' was not declared in this scope
shared_ptr<string> message1(new string("Hello Raspberry Pi C++11"));
I'm compiling with this command: g++ -std=c++11 -o test test.cpp
G++ version is g++ (Raspbian 4.8.2-21~rpi3rpi1) 4.8.2
Please help.
You need to add the memory header at the beginning of your file.
#include <memory>
if above solution does not work even after include of header, please ensure that to compiler you are passing argument --std=c++11
In case, it is being compiled with gcc, you should include header tr1 headers i.e. #include instead of and std::tr1::shared_ptr respectively.
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