const成员函数、inline成员函数、static成员函数中关键字的位置
来源:互联网 发布:阿里云ecs搭建ss 编辑:程序博客网 时间:2024/05/16 08:40
const成员函数
在类中用const修饰成员函数名,
在类外同样需要使用const修改其成员函数名。
否则,编译器会把它看成一个不同的函数。
当然,如果const成员函数直接在类中定义,
类外的声明也就不需要了。
class Player{public:Player(std::string name, int age) : m_strName(name), m_nAge(age){}std::string GetName() const { return m_strName; }int GetAge() const;private:const std::string m_strName;int m_nAge;};int Player::GetAge() const {return m_nAge;}
inline成员函数
如果成员函数直接在类中定义,那么该成员函数直接就是inline成员函数。
使用或者不使用inline对之进行声明效果一样。
如果成员函数的定义在类外进行,那么要使它成为inline函数,
需在它的定义中用inline进行声明,而不是声明中进行声明。
static成员函数
static需要在类申明中进行声明。
如果其定义在类外,类外的定义无需使用static进行声明。
class Player{public:Player() { ++ m_nCnt; }static int GetCnt();private:static int m_nCnt;};int Player::m_nCnt = 0;int Player::GetCnt(){return m_nCnt;}
0 0
- const成员函数、inline成员函数、static成员函数中关键字的位置
- const/static 成员函数
- const成员函数与static成员函数
- 修饰类成员函数的几个关键字:inline, const, explicit, static, virtual
- c++中static成员函数和const成员函数特点
- 类的static成员函数和const成员函数
- 类的static成员函数和const成员函数
- 含有const关键字成员函数
- const关键字类成员函数
- const static与类的数据成员,成员函数,对象
- inline成员函数
- inline 成员函数
- inline成员函数
- inline 成员函数
- inline成员函数
- static成员函数成员变量
- static数据成员、成员函数的问题
- static数据成员、成员函数的问题
- 查询在2月份入职的所有员工信息
- uvalive 3485 - 数值积分
- HDU 2547 无剑无我(水~)
- 产生一个螺旋矩阵
- 系统程序员成长计划读后感
- const成员函数、inline成员函数、static成员函数中关键字的位置
- postMessage安全性问题
- java篇 【14】Java 继承
- 关于应急道占用问题
- 【Cpp】删除字符串空格
- 安卓控件使用系列20:ProgressBar进度条控件的使用方法
- 弱校联萌十一大决战之强力热身 C题
- Ext.grid.plugin.RowExpander的简单用法
- Spark On YARN内存分配