在c++类内部使用的默认值
Default value used inside a C++ class
我一直在阅读代码,我对代码中的一行感到困惑:下面是部分代码:
class mom_set
{
public:
int nm;
int *mom_ind,*mode_off,*mode_count,**mode;
int n_mom,n_eff;
int order;
.......
.....
mom_set(int nm0=9):nm(nm0)
{ mom_ind=new int[(nm*2+1)*(nm*2+1)*(nm*2+1)];
mode_off=new int[3*nm*nm+1];
mode=new int*[3*nm*nm+1];
mode_count=new int[3*nm*nm+1];
clear();}
......
.....
};
我不确定如何解释这行"mom_set(int nm0=9):nm(nm0)". 你能解释一下吗?
mom_set:与类名相同意味着它是构造函数
(int nm0=9):参数列表。一个可选的int
类型的参数。如果没有传递,这个参数默认值为9
::构造函数初始化列表起始
nm(nm0):成员nm
被初始化为值nm0
{…}:构造函数主体的剩余部分
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 具有默认值的引用获取函数
- 当给定默认值时,为什么此模板参数推导失败
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 格式化浮点值:返回默认值
- 如何将数组部分初始化为某个默认值?
- asn1c 不会从 asn.1 模块中提取八位字节字符串的默认值
- 创建一个包含 c++ 默认值的环境文件
- C++(和 ROS) - 包含与前向声明引用,设置默认值和类型定义
- Makefile g++ 使用命令行中的 -D 变量进行编译,默认值
- Switch 语句(字符串)一直选择默认值,除非其为零
- 如何使用默认值将枚举声明为 extern
- 如何在提升程序选项中设置矢量<矢量>的默认值<string>
- 如何使用默认值为构造函数中的枚举赋值?
- 变量始终在函数中重置为默认值
- 如何在C++中提供模板化函数作为另一个函数的参数,默认值?
- 函数不返回默认值
- 具有公共范围与专用范围的默认值的C++的不同行为
- C++:使用内部typedef(如果traits类或默认值中可用)
- 在c++类内部使用的默认值