1,问题引入
最近有人问我一个问题:他在写单向链表的时候,在程序里显式调用了析构函数,程序就报错了,不调用析构函数的时候还好好的(他写的链表的增删改查等成员方法都没有错误的前提下),为什么呢?今天我们就带大家用简单的例子来一探究竟。
2,问题探究
先插入以下的代码作为讨论;
#include<iostream>
#include<string>
using namespace std;
//定义一个简单的学生类
class Student
{
public:
Student (int id = 0, const char* name = "") //默认值:id=0,name=nullptr
{