跳转到内容
新建笔记

C++特性

重载类型描述代码示例
函数重载允许定义多个同名函数,参数列表不同。void print(int a); void print(double a); void print(const std::string& a);
运算符重载自定义已有运算符的行为,适用于自定义类型。Point operator+(const Point& p) const;
构造函数重载定义多个构造函数,每个构造函数有不同的参数列表。Rectangle(); Rectangle(int w, int h);
类型转换重载定义类型转换操作符,允许对象转换为其他类型。operator std::string() const;
析构函数重载C++11引入,允许定义多个析构函数,适用于基类和派生类。~Base(); ~Derived();