class Student {
friend ostream& operator<<(ostream &out, const Student &object);
public:
Student() {
age = 0;
name[0] = '\0';
}
void print() {
cout << name << ", " << age << endl;
}
Student(int _age, const char *_name) {
age = _age;
name = new char[strlen(_name)];
strcpy_s(name, strlen(_name) + 1, _name);
}
~Student() {
if (name!=NULL)
{
cout << "stubent析构函数" << endl;
delete[] name;
name = NULL;
}
}
private:
int age;
char *name = NULL;
};
ostream& operator<<(ostream &out, const Student &object) {
out << "(" << object.name << " , " << object.age << ")";
return out;
}
int main(void) {
Student s1(18, "ckh");
cout << s1 << endl;
system("pause");
return 0;
}