- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Object-Oriented Programming 计算机科学与技术学院 刘培强 liupq@126.com Chapter2 From C to C++ 2.1 Namespaces 名字空间 Namespaces - functions A namespace is a scope. C++ provides namespaces to prevent name conflicts. Namespaces - functions A namespace is a mechanism for expressing logical grouping. That is, if some declarations logically belong together to some criteria(准则), they can be put in a common namespace to express that fact. That is, the namespace is the mechanism for supporting module programming paradigm(范型). 同一 namespace 中的声明在概念上属于同一个逻辑实体。 Namespaces - functions Namespaces – scope resolution operator The scope resolution operator (域解析符):: occurs between the namespaces name and the variable. Namespaces – using declaration 由于各个 namespace 之间经常会出现互相使用对方成员的情况,如果一使用就要约束,既繁琐又容易出错。因此,C++提供了几种“有限的统一”约束的机制。 A using declaration(using声明) applies a single item in the namespace. Namespaces – using directive Using directive(using 指示)is equivalent to a using declaration for each item in a namespace. A using-directive makes names from a namespace available almost as if they had been declared outside their namespace. Namespaces – using directive A namespace is a scope. Thus, “namespace is a very fundamental and relatively simple concept. The larger a program is, the more useful namespaces are to express logical separations of its parts. Ideally(理想地), a namespace should [1] express a logically coherent (相关的) set of features. [2] not give users access to unrelated features, and [3] not impose a significant notational burden on users. Namespaces - std C++’s std namespaces includes all of the standard libraries. 2.2 Introduction to C++ Input/Output C++ Input/Output basic concepts In C++, input/output is treated as a stream of consecutive bytes(连续的字节流). Thus C++ input/output is called stream input/output. C++ Input/Output basic concepts The header iostream must be included to use C++ standard input/output. cin: the standard input object cout: the standard output object
文档评论(0)