C++ 11三个新特性的简单使用 - std::function、lambda 表达式、智能指针
生活随笔
收集整理的這篇文章主要介紹了
C++ 11三个新特性的简单使用 - std::function、lambda 表达式、智能指针
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? 使用Dev C++;先設置Dev C++ 支持 C++ 11;見此文后部;
https://blog.csdn.net/bcbobo21cn/article/details/111466179
?
1 std::function
#include <functional>#include <iostream>using namespace std;int myadd(int a, int b){return a+b;}int main(){std::function<int(int, int)>func = myadd;cout<<func(4, 7)<<endl; // 11system("pause");return 0;}2 lambda表達式
#include <functional>#include <iostream>using namespace std;int main(){int xx= 10;auto myf = [xx] (int a) { cout << "hello, world, Lambda, " << a << ", " << xx << endl; }; myf(99099); system("pause"); return 0;}3 智能指針
#include <memory>#include <iostream>using namespace std;int main(){std::shared_ptr<int> p1(new int(99099));std::shared_ptr<std::string> ss(new std::string("AAABBB"));cout << p1 << ", " << p1.use_count() << endl;cout << ss << ", " << ss.use_count() << endl;auto a1 = std::make_shared<int>(9979);cout << a1 << endl;system("pause"); return 0;}?
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的C++ 11三个新特性的简单使用 - std::function、lambda 表达式、智能指针的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JSP JSTL标签库基本使用
- 下一篇: 数据库多对多关系示例 - 使用sqlit