类的多态
运算符重载 不能重载的运算符 类属关系运算符“.” 成员指针运算符“.*” 作用域分辨符“::” 三目运算符“?:” 重载运算符 重载运算符函数必须要有重载的类在参数里面 成员重载运算符 调用时,必须是类对象进行调用,且会将自己自动传入做 this 双目运算符操作时,该类对象必须出现在左边,以进行调用 单目运算符操作时,int有是后置++/--,无是前置++/-- 非静态成员 #include using namespace std; class Clock { public: Clock(int hour = 0, int minute = 0, int second = 0); void showTime() const; Clock &operator++(); //前置单目运算符 Clock operator++(int); //int用于区分前置还是后置运算符 后置单目运算符 private: int hour, minute, second; }; void Clock::showTime() const{ cout 非成员运算符 用来解决调用对象不是类对象的情况(但参数还是要有类对象存在) 非成员 #include using namespace std; //非成员函数解决"复数+类"的情况,成员的运算符重载只能做到第一个参数是类类型的 class Complex