c++11学习一

1 函数模板

namespace tl
{
	template <typename T> void swap(T & t1, T & t2)
	{
		T tmpT;
		tmpT = t1;
		t1 = t2;
		t2 = tmpT;
	}
}

2 类模板

template <class T> class Stack {
    public:
        Stack();
        ~Stack();
        void push(T t);
        T pop();
        bool isEmpty();
    private:
        T *m_pT;        
        int m_maxSize;
        int m_size;
};

3 类型转换

关键字说明
static_cast用于良性转换,一般不会导致意外发生,风险很低。
const_cast用于 const 与非 const、volatile 与非 volatile 之间的转换。
reinterpret_cast高度危险的转换,这种转换仅仅是对二进制位的重新解释,不会借助已有的转换规则对数据进行调整,但是可以实现最灵活的 C++ 类型转换。
dynamic_cast借助 RTTI,用于类型安全的向下转型(Downcasting)。

4 空指针nullptr

c++11弃用NULL,使用nullptr,避免冲突,NULL可以转化未数值0,nullptr只表示空指针

5 常量表达式constexpr

constexpr int a = 5;

int arr[a]; //合法

6 auto自动类型转换

	auto i = 5;
	auto ci = new auto(5);
	auto cj = new int[5];

7 区间迭代
区间迭代是指基于范围的 for 循环

	for(auto & item:arr)
	{
		cout<<item<<endl;
	}

final 则是为了防止类被继续继承以及终止虚函数继续重载引入的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

feng_blog6688

只需一个赞,谢谢你的鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值