C++11新特性(四)static_assert, share_ptr, unique_ptr简单使用
来源:互联网 发布:gta5女人物捏脸数据 编辑:程序博客网 时间:2024/06/06 01:40
// auto also as the type of turn, as long as appoint the type
#include <iostream>
auto add(int a,int b)->int
{
return a + b;
}
int main()
{
static_assert(444 <9000, "too bigger");
auto result = add(1000,200);
std::cout << result <<std::endl;
/*Section of the shared_ptr*/
std::shared_ptr<int> ptr(newint(100));
std::cout << *ptr <<std::endl;
std::shared_ptr<int> other = ptr;
*other =200;
std::cout << *ptr <<std::endl;
auto value = std::make_shared<int>(300);
std::cout << *value <<std::endl;
/*Section of the unique_ptr*/
std::unique_ptr<int> pn1(newint(2));
std::unique_ptr<int> pn2 = std::move(pn1);// transfer ownership
if (!pn1) {
std::cout <<"It is null" << std::endl;
}
/*Section of the weak_ptr*/
auto p = std::make_shared<int>(33);
std::weak_ptr<int> wp = p;
{
auto sp = wp.lock();
std::cout << *sp << std::endl;
}
p.reset();
if(wp.expired())
std::cout <<"expired" << std::endl;
return 0;
}
- C++11新特性(四)static_assert, share_ptr, unique_ptr简单使用
- c++11新特性--static_assert
- c++11新特性--static_assert
- 【C/C++】智能指针auto_ptr,share_ptr,unique_ptr
- 【C++11】新特性——unique_ptr
- C++ 0x 新特性(4):Static_assert
- 【C++11新特性】 C++11智能指针之unique_ptr
- 【C++11新特性】 C++11智能指针之unique_ptr
- C++11新特性之智能指针(shared_ptr/unique_ptr/weak_ptr)
- C++11新特性(二)override, final 简单使用
- Oracle 数据库12c新特性总结(四)
- C+11 新特性
- java8新特性(四):Stream流的使用
- c++特性:static_assert
- 【C++】C++11新特性 之 lambda表达式的使用
- [c++]Dev-c++使用C++11新特性
- c++智能指针(四)之unique_ptr
- C++11新特性(一)auto for( : )语句简单使用
- 了解网站页面的点击情况
- Android SDK开发包国内下载地址
- 网站的活跃用户与流失用户
- ACM水题系列 HDOJ2673
- ATSC制数字电视机顶盒研究
- C++11新特性(四)static_assert, share_ptr, unique_ptr简单使用
- ACM水题系列 HDOJ2093
- 如何用SQL语句批量替换数据库字符串
- ch13.JSP标准标签库
- JS中Array数组的三大属性用法
- 键盘的关闭打开通知
- 《iOS开发指南:从零基础到App Store上架(第2版 )(3).pdf》
- Flex动态获取应用部署的项目名称和地址栏的URL
- 『ANDROID』使用AnimationDrawable简单的多图片切换