Creating objects on stack or heap
Posted cxchanpin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Creating objects on stack or heap相关的知识,希望对你有一定的参考价值。
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();
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的主要内容,如果未能解决你的问题,请参考以下文章
2. creating and destroying objects
Effective Java P2 Creating and Destroying Objects
System Operations on AWS - Lab 1W - Creating EC2 (Windows)
(Les10 Creating Other Schema Object)[20171213]
Creating a Physical Standby from Primary on Version 12c (Doc ID 1570958.1)
[Creating an image format with an unknown type is an error] on cordova, ios 10