linux中vi的替换用法
构造函数

const总结

yichen posted @ 2014年2月22日 21:52 in Essay , 560 阅读

1

1.常量

声明格式:const <数据类型> <常量名> = <表达式>;常量定义时必须初始化。

2.常指针

声明格式:<数据类型> *const <指针名> = <地址>;指针本身的值不能改变。

3.指向常量的指针

声明格式:const <数据类型> *<指针名> = <常量值>;指针指向的值不能改变。

4.常引用

声明格式:const <数据类型> &<引用名>;常为函数参数,目地保护实参

5.常对象

声明格式:const <类名> <对象名> = <初始化值>; 或 const <类名> <对象名>(<初始化值>);

1)它的数据成员(公有or私有)的值在对象的生存期不能改变,故必须进行初始化,且不能更新。

2)由于无法预料哪些成员函数会改变数据成员的值,故不能用常对象调用普通成员函数,但可调用常成员函数。

3)如若需要改变常对象中某个数据成员值,可将其声明为mutable,如:mutable int count;修改其值是通过调用声明为const的常成员函数的。

6.常数据成员

声明格式:const int <变量名>; 构造函数通过成员初始化列表对其初始化。

7.常成员函数

声明格式:<数据类型> <函数名> (<参数列表>) const; 在声明和定义时都要有const,调用时不必。另外其不能调用其他非const成员函数。

数据成员 非const成员函数 const成员函数
非const数据成员 可引用,可改值 可引用,不可改值
const数据成员 可引用,不可改值 可引用,不可改值
const对象的数据成员 不允许引用 可引用,不可改值

通常把不允许修改数据成员的函数设置为常成员函数,把不允许修改成员的对象设为常对象,常对象只能访问常成员函数。注意:const可以实现成员函数重载。如:void print();-->普通对象调用;void print() const;-->常对象调用。

Eg:

(1) const int* p = &a;

(2) int* const p = &b;

(3) const int* const p = &c;

 

Avatar_small
AP 10th Civics Model 说:
2022年9月17日 07:11

Department of Education and Secondary Education Board has designed the AP SSC Civics Model Paper 2023 Pdf with answers for Telugu Medium, English Medium & Urdu Medium Students of the State Board. Every year there are a huge number of teaching staff and educational portals of the state have suggested the practice question bank with revision questions for both medium students of the board. AP 10th Civics Model Paper In civics, students learn to contribute to public processes and discussions of real issues. Students can also learn civic practices such as voting, volunteering, jury service, and joining with others to improve society. Civics enables students not only to study how others participate but also to practice participating and taking informed action themselves.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter