
本文共 3315 字,大约阅读时间需要 11 分钟。
C++������������������������������������������������������������������������������������������������������������������������������������������������������������������~���������������������������������������������������������������������������������������������������������
���C++���������������������������������������������������������������������������������������������������������������new������������������������������delete���auto_ptr������������������������������������������������������������������������������������������������������������������������������������������������
���������������������
class Student { private: double * scores; public: Student(int len) { scores = new double[len]; } ~Student() { delete scores; }};
- ������������������������������������������������������������������������������������������������������������������������������������������������������������������
- ���������������������������������������������������������������������������������������stack������heap������������������������������������
- RAII������������������������������C++���RAII���������������������������������������������������������������������������������������������������������������������������
������������������������������
������������������������������������~���������������������������������������������������������������������������������������������������������������������������������������������������������������������������
class MyClass { ... ~MyClass(); ...};
������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������
������������������������������C++���������������������������������������������������������������������������������������������������
#include "Student.h"#includeusing namespace std;// ������.Student���������Student Student(int age) { // ��������������� Student stu(age); cout << "���������������" << endl; return stu;}// ������new���������������Student * createStudentWithHeap() { Student * stu(new Student("������", "������������")); return stu;}int main() { // ��������������� Student stu1; // ��������� cout << "������������" << endl; // ������������������ Student * stuHeap = new Student("������", "������������������"); cout << "������������" << endl; // ������������ delete stuHeap; return 0;}
������������
������������������������C++���������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
