关于C++11新特性 智能指针、auto

智能指针

太长了

Auto

auto的自动类型推断发生在编译期,所以使用auto并不会造成程序运行时效率的降低

auto和其他变量类型有明显的区别:

1.auto声明的变量必须要初始化,否则编译器不能判断变量的类型。

2.auto不能被声明为返回值,auto不能作为形参,auto不能被修饰为模板参数

#include<iostream>
auto show(int m)->decltype(1.0){return m;}
auto show()->decltype(1l){return 11;}
int main()
{
    std::cout<< show(10) << std::endl;
    long (*a)() = show;
    //int (*b)() = show;
    std::cout<<a()<<std::endl;
    std::cout<<b()<<std::endl;
    return 0;
}

参考链接:

【1】https://www.jianshu.com/p/a462a35c9481

【2】https://blog.csdn.net/k346k346/article/details/81478223

【3】https://blog.csdn.net/flowing_wind/article/details/81301001

【4】我喜欢这个https://blog.csdn.net/weizhengbo/article/details/68957993

【5】autohttps://blog.csdn.net/qq_31930499/article/details/79948906

【6】autohttps://blog.csdn.net/rubikchen/article/details/89918876

原文地址:https://www.cnblogs.com/lalalatianlalu/p/11627832.html