第4章运算符重载-1.pptVIP

  • 4
  • 0
  • 约8.78千字
  • 约 45页
  • 2018-01-05 发布于河南
  • 举报
第4章运算符重载-1

第4章运算符重载 4.1什么是运算符重载 4.2运算符重载的方法 4.3重载运算符的规则 4.4运算符重载函数作为类成员函数和友元函数 4.5重载双目运算符 4.6重载单目运算符 成员函数实现运算符的重载时,参数只能有二种情况: 没有参数,通常对于只有一个操作数的运算符(如++), 带有一个参数,通常对于有二个操作数的运算符。 具体见P125表4.1 问题:指出下面程序的错误 class Str{ int Length; char *Sp; public: Str(){ } Str(char *string){ if(string){Length=strlen(string); Sp=new char[Length+1]; strcpy(Sp,string); } else Sp=0; } void Show(void){coutSpendl;} ~Str(){ if(Sp) delete [ ]Sp; } }; void main(void) { Str s1(Study C++); Str s2; s2=s1; s1.Show (); s2.Show (); } 问题:写出程序的输出 class room{ float Length; float Wide; public:room(f

文档评论(0)

1亿VIP精品文档

相关文档