输出结果:
Person()…
~Person()…
请按任意键继续. . .
[……]
1、String.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #pragma once #include <iostream> using namespace std; class String { friend ostream &operator << (ostream &, String &); private: char *m_name = NULL; char *setM_name(const char *cstring); char *strAppend(const char *, const char *); public: String(const char *cstring = ""); String(const String &); ~String(); bool operator == (String &string); String &operator = (String &string); String &operator = (const char *cstring); String operator + (const char *cstring); String operator + (const String &string); String &operator += (const char *cstring); String &operator += (const String &string); char operator[](int index); bool operator<(const String &string); }; ostream &operator << (ostream &cout, String &string); </iostream> |
2、String.cpp
[……]
1、C++中多态是一种泛型编程思想,虚函数是实现这个思想的语法基础;
2、虚函数列表简称虚表,出现在对象的头部,即虚表的首地址即对象地址;
3、通过创建好的对象,可以得到虚表,从而通过偏移可获取所有虚函数的地址;
4、示例代码:
5、执行结果:
[……]