zoukankan      html  css  js  c++  java
  • 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();

    }


    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.

  • 相关阅读:
    linux sed命令详解
    SQL注入基础知识
    DC-7
    DC-6
    DC-5
    DC-4
    DC-3
    DC-2
    pentestlabs
    任意文件读取和下载
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/7364440.html
Copyright © 2011-2022 走看看