⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hour10_3.cpp

📁 C++学习的有利助手
💻 CPP
字号:
 // Listing 10.2
 // Accessing members of objects on the heap
 #include <iostream>
 using std::endl;
 class SimpleCat
 {
 public:
     SimpleCat() {itsAge = 2; }
     ~SimpleCat() {}
     int GetAge() const { return itsAge; }
     void SetAge(int age) { itsAge = age; }
 private:
     int itsAge;
 };

 int main()
 {
     SimpleCat * Frisky = new SimpleCat;

   // -> below was replaced with (*  ).
   // To me, the points-to operator ( -> ) is clearly easier
   // to read and therefore more meaningful.
   
     std::cout << "Frisky is " << (*Frisky).GetAge()
               << " years old" << endl;

     (*Frisky).SetAge(5);
     std::cout << "Frisky is " << (*Frisky).GetAge()
               << " years old" << endl;

     delete Frisky;
     return 0;
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -