C++ shared_ptr 编译 error ‘shared_ptr’ was not declared in this scope修复
2017-02-21 10:36
1011 查看
#include<iostream> #include<cstring> #include<string> #include<memory> using namespace std; class Simple { public: Simple(int p = 0) { number = p; std::cout << "Simple::" << number << std::endl; } ~Simple() { std::cout << "~Simple::" << number << std::endl; } void PrintSomething() { std::cout << "PrintSomething:" << info_extend.c_str() << std::endl; } std::string info_extend; int number; }; void TestSharedPtr() { std::shared_ptr<Simple> my_memory(new Simple(1)); if(my_memory.get()) { my_memory->PrintSomething(); my_memory.get()->info_extend = "Additon"; my_memory->PrintSomething(); (*my_memory).info_extend += "other"; my_memory->PrintSomething(); } } int main() { TestSharedPtr(); return 0; }
编译:g++ -std=c++11 -o test.exe ptr.cpp
[jingsia@localhost ~]$ ./test.exe
Simple::1
PrintSomething:
PrintSomething:Additon
PrintSomething:Additonother
~Simple::1
相关文章推荐
- ndk编译错误:error: 'nullptr' was not declared in this scope
- linux 编译ffmpeg 出错:error: 'UINT64_C' was not declared in this scope
- 编译是报error: 'EVNET_COME_TO_FOREGROUND' was not declared in this scope
- linux 编译ffmpeg 出错:error: 'UINT64_C' was not declared in this scope
- Arduino- 编译引用 IRremote 出现 error: ‘TKD2′ was not declared in this scope
- 编译opencv 2.4.13error:1 /usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
- 调用ffmpeg库编译时出现common.h:175:47: error: 'UINT64_C' was not declared in this scope
- c++ error: 'malloc' was not declared in this scope
- 【Cocos2d-x】编译Android工程时提示error: 'GL_LINE_SMOOTH' was not declared in this scope
- 解决Cygwin编译cocos2dx 遇到的 error: 'UINT64_C' was not declared in this scope 问题
- Code::Block 'shared_ptr' was not declared in this scope
- 用g++ 编译 ffmpeg 编译出现 error: 'UINT64_C' was not declared in this scope 或 missing -D__STDC_CONSTANT_MACROS
- c++中[Error] 'cin' was not declared in this scope 是什么意思
- c++ - fcgio.cpp:50: error: 'EOF' was not declared in this scope - Stack Overflow
- opencv 2.3交叉编译时出现dist.h:63:68: error: 'fabsl' was not declared in this scope
- error: ‘exit’ was not declared in this scope
- error: ‘exit’ was not declared in this scope 的解决方法
- error: 'ff_get_buffer' was not declared in this scope
- error: 'UINT64_C' was not declared in this scope
- error: ‘errno’ was not declared in this scope