内容简介:头文件的顺序.1. 系统/基本头文件2. 其他工程头文件
头文件的顺序.
1. 系统/基本头文件
2. 其他工程头文件
3. 本工程头文件
4. 本类头文件.
类定义中的成员变脸和成员函数排列顺序
1. 枚举/结构体, 固定使用public类型, 排在最前
2. private 成员 变量
3. protected 成员变量
4. public 成员变量
5. private 成员函数
6. protected 成员 函数
成员 函数
细分顺序
本类const 成员 函数
本类非const 成员 函数
本类const虚 函数
本类非const 虚 函数
基类const 成员 函数
基 类非const 成员 函数
点击( 此处 )折叠或打开 迭代器的使用范例.
- # include < iostream >
- # include < map >
- using namespace std ;
- class CMapExa
- {
- public :
- void OnInit ( ) ;
- void DelFunConfuse ( ) ;
- void DelFunCorrect ( ) ;
- void Show ( ) ;
- private :
- typedef map < int , int > MAP_DATA ;
- MAP_DATA m_map ;
- } ;
- void CMapExa : : OnInit ( )
- {
- m_map . insert ( MAP_DATA : : value_type ( 1 , 1 ) ) ;
- m_map . insert ( MAP_DATA : : value_type ( 2 , 2 ) ) ;
- m_map . insert ( MAP_DATA : : value_type ( 3 , 3 ) ) ;
- }
- void CMapExa : : DelFunConfuse ( ) //不好的方式
- {
- for ( MAP_DATA : : iterator it = m_map . begin ( ) ; it ! = m_map . end ( ) ; )
- {
- m_map . erase ( it + + ) ; //容易错误使用为 m_map . erase ( it ) ;
- }
- }
- void CMapExa : : DelFunCorrect ( ) //建议的方式
- {
- MAP_DATA delMap ;
- for ( MAP_DATA : : iterator it = m_map . begin ( ) ; it ! = m_map . end ( ) ; + + it ) {
- delMap [ it - > first ] = it - > second ;
- }
- for ( MAP_DATA : : iterator it = delMap . begin ( ) ; it ! = delMap . end ( ) ; + + it ) {
- MAP_DATA : : iterator itDel = m_map . find ( it - > first ) ;
- if ( itDel ! = m_map . end ( ) )
- m_map . erase ( itDel ) ;
- }
- delMap . clear ( ) ;
- }
- void CMapExa : : Show ( )
- {
- for ( MAP_DATA : : iterator it = m_map . begin ( ) ; it ! = m_map . end ( ) ; it + + )
- {
- cout < < it - > first < < endl ;
- cout < < it - > second < < endl ;
- }
- }
- int main ( )
- {
- CMapExa objMapExa ;
- objMapExa . OnInit ( ) ;
- objMapExa . DelFunCorrect ( ) ;
- //objMapExa . DelFunConfuse ( ) ;
- objMapExa . Show ( ) ;
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Crontab命令格式与范例
- Crontab命令格式与范例
- ls 命令的 20 个实用范例
- 大小端序分析以及 go 范例
- PHP设计模式范例 — DesignPatternsPHP(1)创建型设计模式
- Oracle数据库文件:listener.ora和tnsnames.ora范例
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Web Anatomy
Robert Hoekman Jr.、Jared Spool / New Riders / 2009-12-11 / USD 39.99
At the start of every web design project, the ongoing struggles reappear. We want to design highly usable and self-evident applications, but we also want to devise innovative, compelling, and exciting......一起来看看 《Web Anatomy》 这本书的介绍吧!