函数声明后面的const用法
来源:互联网 发布:32bit安装tensorflow 编辑:程序博客网 时间:2024/04/30 14:27
在类成员函数的声明和定义中,
const的函数不能对其数据成员进行修改操作。
const的对象,不能引用非const的成员函数。
#include <stdio.h>#include <string.h>#include <iostream.h>class A{ private: int m_a; public: A() : m_a(0) {} int getA() const { return m_a; //同return this->m_a; } int GetA() { return m_a; } int setA(int a) const { m_a = a; //这里产生编译错误,如果把前面的成员定义int m_a;改为mutable int m_a;就可以编译通过。 } int SetA(int a) { m_a = a; //同this->m_a = a; }}; int main() { A a1; const A a2; int t; t = a1.getA(); t = a1.GetA(); t = a2.getA(); // t = a2.GetA(); //a2是const对象,调用非const成员函数产生编译错误。 return 1; }
0 0
- 函数声明后面的const用法
- 函数声明后面的const用法
- 函数声明后面的const用法
- 函数声明后面的const用法
- 函数声明后面的const用法
- C++ 函数声明后面的const用法
- 函数声明后面的const用法
- 函数声明后面的const用法
- 函数声明后面的const用法 void function() const{}
- 函数声明后面的const是什么意思
- 函数后面加const的用法
- 类中成员函数声明后面的const的含义!
- 函数声明时,名后面的const的意思
- 为什么在函数的声明后面还有一个 const?
- C++函数声明的时候后面加const代表什么
- C++函数声明的时候后面加const
- C++函数声明的时候后面加const代表什么?
- 为什么在函数的声明后面还有一个 const?
- MUI开发注意事项
- 软件测试和软件调试的区别
- Message LongText(消息的详细长文本)
- iOS当UITableViewCell被选中或者高亮的时候,它的所有子view的颜色都会改变
- Unix/Linux开源世界资源链接汇总
- 函数声明后面的const用法
- (leetCode)Count and Say --- 统计读
- ABAP长文本
- c语言之字符串
- Spring MVC拦截器通过注解方式实现防止表单重复提交
- iOS使用NSMutableSet记录cell控件选中状态避免cell重用问题
- UITabbarController
- 史上最全的机器学习资料(上)
- 【caffe-Windows】微软官方caffe之 Python接口配置及图片生成实例