C++运算符载.ppt

  1. 1、本文档共107页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C运算符载

String类的使用 int main() { ??? String s1( happy ), s2( birthday ), s3; ?? // test overloaded equality and relational operators ?? cout s1 is \ s1 \; s2 is \ s2 ?????? \; s3 is \ s3 \ ?????? \nThe results of comparing s2 and s1: ?????? \ns2 == s1 yields? ( s2 == s1 ? true : false ) ?????? \ns2 != s1 yields?? ( s2 != s1 ? true : false } ?????? \ns2 s1 yields??? ( s2 s1 ? true : false ) ?????? \ns2 s1 yields ?? ( s2 s1 ? true : false ) ??????? \ns2 = s1 yields”? ( s2 = s1 ? true : false ) ?????? \ns2 = s1 yields? ( s2 = s1 ? true : false ); 上页执行结果 Conversion constructor: happy Conversion constructor: birthday Conversion constructor: sl is happy; s2 is birthday; s3 is? The results of comparing s2 and s1: s2 == s1 yields false s2 != s1 yields true s2 sl yields false s2 sl yields true s2 = s1 yields false s2 = s1 yields true // test overloaded String empty (!) operator ?? cout \n\nTesting !s3:\n; ?? if ( !s3 ) { ???? cout s3 is empty; assigning s1 to s3;\n; ???? s3 = s1;?????????? // test overloaded assignment ???? cout s3 is \ s3 \; ?? } 上页执行结果 Testing !s3: s3 is empty; assigning s1 to s3; operator = called s3 is happy ?? cout \n\ns1 += s2 yields s1 = ; ?? s1 += s2;???????????? // test overloaded concatenation ?? cout s1; ?? cout \n\ns1 += \ to you\ yields\n; ?? s1 += to you;?????? // test conversion constructor ?? cout s1 = s1 \n\n; 上页执行结果 s1 += s2 yields s1 = happy birthday s1 += to you yields Conversion constructor: to you Destructor: to you s1 = happy birthday to you // test overloaded function call operator () for substring ?? cout The substring of s1 starting at\n ??????? location 0 for 14 characters, s1(0, 14), is:\n ??????? s1( 0, 14 ) \n\n; // test substring to-end-of-String option ?? cout The substring of s1 starting at\n ??????? location 15, s1(15, 0), is: ??????? s1( 15, 0 ) \n\n;? // 0 is to end of string 上页执行结果 Conversion constructor: The substring of sl starting at location 0

文档评论(0)

173****7830 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档