📄 heapaccess.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;
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 + -