首页 > 其他 > 详细

Creating objects on stack or heap

时间:2017-08-15 13:11:01      阅读:234      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!