运行结果: 请输入一个整数和一个字符: 4 G Node constructor is running... Linklist constructor is running... Node constructor is running... Node constructor is running... Node constructor is running... After Insert 4 G 3 F 2 B 1 C After Delete 4 G 3 F 1 C Linklist cloner running... This is Linklist b 4 G 3 F 1 C After Destroy 4 G 根据程序运行的结果,我们发现输出链表b的内容的确和链表a一样了,并且我们可以得到三个结论: (1) 拷贝构造函数可以读出相同类对象的私有成员数据; (2) 拷贝构造函数的实质是把参数的成员数据一一复制到新的对象中; (3) 拷贝构造函数也是构造函数的一种重载。
运行结果: 请输入一个整数和一个字符: 4 G Node constructor is running... Linklist constructor is running... Node constructor is running... Node constructor is running... Node constructor is running... After Insert 4 G 3 F 2 B 1 C After Delete 4 G 3 F 1 C Linklist Deep cloner running... Node constructor is running... Node constructor is running... This is Linklist b 4 G 3 F 1 C After Destroy 4 G This is Linklist b 4 G 3 F 1 C 我们看到,现在即使运行a.Destroy()之后,链表b里面的数据仍然能够正常显示。这是因为深拷贝构造函数是真正意义上的复制了链表a,并且使得链表a和链表b各自独立,互不干扰。这才是自定义拷贝构造函数存在的重要意义。