码迷,mamicode.com
首页 > 编程语言 > 详细

C++智能指针

时间:2019-09-04 21:50:54      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:ring   ace   cout   rds   clu   out   card   game   color   


#include<iostream> #include<memory> using namespace std; class PokerGame{ public: int cards; int mumber; string name; PokerGame(int cards, int mumber){ this->cards = cards; this->mumber = mumber; } void display(){ cout << "cards: " << cards<<" mumber: " << mumber<<" name: " << name<<endl; } }; void Game(shared_ptr<PokerGame> game){ // 智能指针做形参 game->display(); game->cards=45; game->mumber=5; game->name="钓鱼"; game->display(); } int main(){ shared_ptr<PokerGame> game= make_shared<PokerGame>(54,3); game->name = "斗地主"; Game(game); shared_ptr<PokerGame> game2(new PokerGame(30,2)); game2->name = "随便玩"; game2->display(); return 0; }

 

C++智能指针

标签:ring   ace   cout   rds   clu   out   card   game   color   

原文地址:https://www.cnblogs.com/ligei/p/11461204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!