北邮课件--C++(6)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

C++(6)TangXiaoshengBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!!!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.1!!、()!“BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!!C++“BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2!!!namespace-name::member-name!!main()BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!!“!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnnamespaceParser{doubleexpr(bool);doubleprim(boolget){/*…*/}doubleterm(boolget){/*…*/}doubleexpr(boolget){/*…*/}}//namespaceParser{doubleexpr(bool);doubleprim(bool);doubleterm(bool);}//doubleParser::expr(boolget){/*…*/}doubleParser::prim(boolget){/*…*/}doubleParser::term(boolget){/*…*/}namespacename{//}voidParser::logical(bool);//Error,Parserlogical//logicalvoidParser::prim(int);//Error,primboolBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.1!!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnnamespaceLexer{//namespaceenumToken_value{NAME,NUMBER,END,MUL=‘*’};Token_valuecurr_tok;doublenumber_value;stringstring_value;Token_valueget_token(){/*…*/}}doubleParser::term(boolget)//Parser{doubleleft=prim(get);//for(;;)switch(Lexer::curr_tok){//LexercaseLexer::NAME://Lexerleft*=prim(true);////…}/*…*/}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.2!。doubleParser::prim(boolget){if(get)Lexer::get_token();switch(Lexer::curr_tok){caseLexer::NUMBER:Lexer::get_token();//…}}doubleParser::prim(boolget){usingLexer::get_token;usingLexer::curr_tok;if(get)get_token();switch(curr_tok){caseLexer::NUMBER:get_token();//…}}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!ParsernamespaceParser{doubleprim(bool);doubleterm(bool);doubleexpr(bool);usingLexer::get_token;usingLexer::curr_tok;usingError::error;}doubleParser::term(boolget){doubleleft=prim(get);for(;;)switch(curr_tok){caseLexer::MUL:left*=prim(true);break;caseLexer::DIV:if(doubled=prim(true)){left/=prim(true);break;}returnerror(“dividedby0”);/*……*/}}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.3!namespaceParser{doubleprim(bool);doubleterm(bool);doubleexpr(bool);usingnamespaceLexer;usingnamespaceError;}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.4!!!。//namespaceParser{doubleprim(bool);doubleterm(bool);doubleexpr(bool);usingnamespaceLexer;usingnamespaceError;}//namespaceParser{doubleexpr(bool);}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.4.1!”!()()BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn//namespaceParser{//…doubleexpr(bool);//…}//namespaceParser_interface{usingParser::expr;}////namespaceParser_interface{doubleexpr(bool);}doubleParser_interface::expr(boolget){returnParser::expr(get);}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.5。!!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn。//my.hcharf(char);intf(int);classString{/*…*/};//you.hcharf(char);doublef(double);classString{/*…*/};my.hyou.hnamespaceMy{charf(char);intf(int);classString{/*…*/};}namespaceYou{charf(char);doublef(double);classString{/*…*/};}1My::f(char),You::f(double)2usingMy::f;usingYou::String;3usingnamespaceMy;usingnamespaceYou;BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.5.1!。!“!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn#include“header.h”namespaceMine{inta;voiff(){/*…*/}intg(){/*…*/}}//#include“header.h”namespace{inta;voiff(){/*…*/}intg(){/*…*/}}#include“header.h”namespace$$${inta;voiff(){/*…*/}intg(){/*…*/}}usingnamespace$$$;//$$$////////。BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.6!TTnamespaceChrono{classDate{/*…*/};booloperator==(constDate&,conststd::string&);std::stringformat(constDate&);}voidf(Chrono::Dated,inti){std::strings=format(d);//Chrono::format()std::stringt=format(i);//Error:int//format()}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!using!voidf(Chrono::Dated,std::strings){if(d==s){//…}elseif(d==“August4,1914”){//…}}//Chronooperator==BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.7!(namespaceA)(namespaceAmerican_Telephone_and_Telegraph)!“BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnnamespaceATT=American_Telephone_and_Telegraph;ATT::Strings3=“Grieg”;ATT::Strings4=“Nielsen”;namespaceLib=Foundation_library_v2r11;//…Lib::sets;Lib::Strings5=“Sibelius”;//Foundation”//Lib////BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn8.2.8!namespaceHis_string{classString{/*…*/};Stringoperator+(constString&,constString&);Stringoperator+(constString&,constchar*);voidfill(char);}namespaceHer_vector{templateclassTclassVector{/*…*/};}namespaceMy_lib{usingnamespaceHis_string;usingnamespaceHer_vector;voidmyfct(String&);}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnvoidf(){My_lib::Strings=“Byron”;////My_lib::His_string::String}usingnamespaceMy_lib;voidg(VectorString&vs){//…myfct(vs[5]);//…}//VectorStringMy_lib//、voidMy_lib::f

1 / 43
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功