码迷,mamicode.com
首页 > 其他好文 > 详细

Creating objects on stack or heap

时间:2017-08-15 13:20:28      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:stack   get   oid   tracking   style   use   move   space   track   

class Player { 
private:
int health; 
int strength; 
int agility;
public:
void move();
void attackEnemy(); 
void getTreasure();


};




int main(){
Player p1;
Player *p2 = new Player;
p1.move();
  p1.getTreasure();
  p2->attackEnemy(); 
  p2->move(); 
  p1.move();

}


When an object is allocated on the stack, we use the dot notation.

When an object is allocated on the heap, we use the arrow natation.

Creating objects on stack or heap

标签:stack   get   oid   tracking   style   use   move   space   track   

原文地址:http://www.cnblogs.com/cxchanpin/p/7364440.html

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