今天布置的,不太能理解,有人能讲讲,就是才学到这构析函数这个地方
#include <iosream>
using namespace std;
class Tree
{
private:
int ages;
public:
Tree() { ages = 0; }
Tree(int initAge) { ages = initAge; }
void grow(int years) { ages += years; }
void showAge() { cout << ages; }
};
int main()
{
Tree t(3);
int y;
cin >> y;
t.grow(y);
t.showAges();
return 0;
}