C++编程(6)

32 break beijing university of posts

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ,因此,如果在使用 一个函数的环境中无法找到它,我们就去查 看它的参数所在的名字空间 namespace Chrono{ void f(Chrono::Date d, int i){ std::string s = format(d); class Date{/*…*/}; bool operator==(const Date&, //Chrono::format() const std::string&); std::string t = format(i); //Error:找不到使用int输入 std::string format(const Date&); //参数的format()版本 } } Beijing University of Posts & Telecommunications Beijing young@buptnet.edu.cn 名字空间示例 名字查找规则能够使程序员节省许多输入,同时也 不必使用using指令污染名字空间,这个规则对于 运算符的运算对象和模板参数特别有用 需要注意的是,名字空间本身必须在作用域里,函 数也必须在它被寻找和使用之前声明 void f(Chrono::Date d, std::strin...
View Full Document

This note was uploaded on 02/10/2014 for the course ECE C++ taught by Professor Xiaoshengtang during the Fall '13 term at BUPT.

Ask a homework question - tutors are online