#include <iostream>
class Student {
public:
Student(const std::string& name_, unsigned age_);
~Student() {}
void output() const {
std::cout << this->name << " " << this->age << std::endl;
++outputCallCount;
}
void printOutputCallCount() {
std::cout << outputCallCount << std::endl;
}
private:
std::string name;
unsigned age;
mutable unsigned outputCallCount = 0;
};
Student::Student(const std::string& name_ = "", unsigned age_ = 0) : name(name_), age(age_) {}
int main() {
Student A("A君", 10);
A.output();
A.output();
A.output();
A.printOutputCallCount();
return 0;
}
标签:std,const,Student,age,函数调用,类内,mutable,name
From: https://www.cnblogs.com/hacker-dvd/p/17385478.html