您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 北邮课件--C++(4)
C++(4)TangXiaoshengBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!!!!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.1!!”BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2!class_namememberobjectpointerexprlvalue!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn(1)class_name::member::namenamespace_name::member::qualified-nameobject.memberpointer[expr]pointer-membertype(expr_list)”expr(expr_list)lvalue++constconst_casttype(expr)lvalue--typeid(type)reinterpret_casttype(expr)type(expr)static_casttype(expr)dynamic_casttype(expr)BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn(2)sizeofexpr++lvaluesizeof(type)--lvalue&lvalue~expr*expr()!expr()newtype-expr()newtype(expr-list)+expr()new(expr-list)type()new(expr-list)type(expr-list)()(type)expr()deletepointer”delete[]pointerBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn(3)object.*printer-to-memberpointer-*pointer-to-memberexpr*exprexpr/expr(”)expr%expr()expr+expr()expr-exprexprexprexprexprexprexprexpr=exprexprexprexpr=exprBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn(4)expr==exprexpr!=exprexpr&exprexpr^exprexpr|exprexpr&&exprexpr||exprBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn(5)expr?expr:exprlvalue=exprlvalue=exprlvalue*=exprlvalue+=exprlvalue=exprlvalue/=exprlvalue-=exprlvalue^=exprlvalue&=exprlvalue|=exprlvalue%=exprthrowexpr。()expr,exprBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cna+b*c//a+(b*c)*p++//p””p+1a=b=c//a=(b=c)a+b+c//(a+b)+ca=bc?d=e:f=g//a=((bc)?(d=e):(f=g))BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.1!”longlongintint!===!sizeofsize_tptrdiff_tcstddefBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnvoidf(intx,inty){intj=x=y;//x=yxint*p=&++x;//pxint*q=&(x++);//(t=x,x=x+1,t)//x++(x)int*pp=&(xy?x:y)//int}voidf(){inti=1;while(0i)i++;cout“ihasbecomenegative!”iendl;}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.2!!。&&||(&&||)!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnintx=f(2)+g(3)//f()g()inti=1;v[i]=i++;//b=(a=2,a+1)//b=3f1(v[i],i++)//”f2((v[i],i++))//”i++a*b/c//(a*b)/c//!=a*(b/c)BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.3!!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnif(i=0||maxi)//if((i=0)||(maxi))//NOTif(i=(0||max)i)if(i&mask==0)//if(i&(mask==0)),20051012if(0=x=99)//if((0=x)=99)//if(0=x&&x=99)if(a=7)//==BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.4!&()|()^()~()(bool,char,short,int,long,enum)!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnenumios_base::iostate{goodbit=0,eofbit=1,failbit=2,badbit=4};state=goodbit;//…stateif(state&(badbit|failbit))//streamunsignedshortmiddle(longa){return(a8)&0xffff;}//a8bit23bitBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.5!++++lvaluelvalue+=1lvalue=lvalue+1--!++--++x()y=++xy=(x+=1)x++xy=x++y=(t=x,x+=1,t)txBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!++--”p++pvoidstrcpy(char*p,constchar*q){while(*p++=*q++);}////intlength=strlen(q);for(inti=0;i=length;i++)p[i]=q[i]//q“BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cninti;for(i=0;q[i]!=0;i++)p[i]=q[i];p[i]=0;//iwhile(*q!=0){*p=*q;p++;q++;}*p=0;////while(*q!=0){*p++=*q++;}*p=0;//(*p++=*q++)*qwhile((*p++=*q++)!=0){}//block//0while(*p++=*q++);BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.6!!new!newdelete!deletenew00BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.6.1”!new”char*s=newchar[32];!”delete[]delete[]s;!newdeletedelete[]new!delete[]new”0BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.6.2!new”void*operatornew(size_t);voidoperatordelete(void*);void*operatornew[](size_t);voidoperatordelete[](void*);!new!new”bad_allocBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnvoidf(){try{for(;;)newchar[10000];}catch(bad_alloc){cerr“Memoryexhausted!”;}}//newvoidout_of_store(){cerr“operatornewfailed:outofstore”;throwbad_alloc();}intmain(){set_new_handler(out_of_store);for(;;)newchar[10000];cout“done!”;}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.7!”void*”I/Ovoid*malloc(size_t);voidf(){int*p=static_castint*(malloc(100));IO_device*dl=reinterpret_castIO_device*(0xff00);}//BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!!static_cast!reinterpret_cast!dynamic_cast()const_cast(constvolatile)BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!C++CT(e)static_cast,reinterpret_cast,const_casteT!C!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.2.8”!eT”T(e)inti=int(1.3)”!T(e)(T)e!”T()Tintj=int();complexz=complex();!0BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn6.3statement:declaration{statement-listopt}try{statement-listopt}handler-listexpressionopt;if(condition)statementif(condition)statementelsestatementswitch(con
本文标题:北邮课件--C++(4)
链接地址:https://www.777doc.com/doc-4043426 .html