一个C++类的注释:
#ifndef __RUNTIMEPARA__HPP
#define __RUNTIMEPARA__HPP
#include <string> //后面会有介绍
#include <map> //C++中的map使用见下文,
class CRuntimePara
{
public:
CRuntimePara(); // 无参数构造函数
~CRuntimePara(); // 析构函数
// 如果创建一个类你没有写任何构造函数,则系统会自动生成默认的无参构造函数,函数为空,什么都不做
CRuntimePara(const CRuntimePara& runPara); // 复制构造函数(也称为拷贝构造函数)
// 复制构造函数参数为类对象本身的引用,用于根据一个已存在的对象复制出一个新的该类的对象,一般在函数中会将已存在对象的数据成员的值复制一份到新创建的对象中
// 若没有显示的写复制构造函数,则系统会默认创建一个复制构造函数,但当类中有指针成员时,由系统默认创建该复制构造函数会存在风险,
// 具体原因请查询 有关 “浅拷贝” 、“深拷贝”的文章论述CRuntimePara& operator=(const CRuntimePara& runPara);
void assign(std::map<std::string,std::string> mapParaValue);
void addString(const std::string& strKey, const std::string& strValue);
void addInt(const std::string& strKey, int iValue);
const std::string& getString(const std::string& strKey); // 等号运算符重载(也叫赋值构造函数)
// 注意,这个类似复制构造函数,将=右边的本类对象的值复制给等号左边的对象,它不属于构造函数,等号左右两边的对象必须已经被创建
// 若没有显示的写=运算符重载,则系统也会创建一个默认的=运算符重载,只做一些基本的拷贝工作 如此处运用,此处最终是想要一个和之前一样的字符串,很有效的用了这个拷贝功能
//下面一个对应的例子,
Complex &operator=( const Complex &rhs )
{
// 首先检测等号右边的是否就是左边的对象本身,若是本对象本身,则直接返回
if ( this == &rhs )
{
return *this;
}
// 复制等号右边的成员到左边的对象中
this->m_real = rhs.m_real;
this->m_imag = rhs.m_imag;
// 把等号左边的对象再次传出
// 目的是为了支持连等 eg: a=b=c 系统首先运行 b=c
// 然后运行 a= ( b=c的返回值,这里应该是复制c值后的b对象)
return *this;
}
const std::string& getString(const std::string& strKey,const std::string& strDefault) ;
int getInt(const std::string& strKey) ;
int getInt(const std::string& strKey,int iDefault);
void debug();
bool addChild(std::string strSvcId, CRuntimePara runPara, std::string strFatherSvcId);
std::map<std::string,CRuntimePara> _mapChild;
private:
std::map<std::string,std::string> _mapParaValue;
};
#endif
---------------------------------------------------------------------------------------------------------------------------
除了作用域的不一样,功能不一样,类型就这几个类型,详情见前文:http://www.cnblogs.com/the-tops/p/5587507.html