首页 > 试题广场 >

已知:print( )函数是一个类的常成员函数,它无返回值,

[单选题]

已知:print( )函数是一个类的常成员函数,它无返回值,下列表示中,( )是正确的

  • void print( ) const;
  • const void print( );
  • void const print( );
  • void print(const);
const在后面,是用来修饰对象中的this,表明这个成员函数不能修改this指向的值,即不能修改对象的值。
发表于 2018-01-22 18:58:24 回复(0)
A  主要是 const 在后面
发表于 2017-07-15 17:22:21 回复(0)
BC是等价的,肯定不可以选的,而D中的参数类型没有const,故也排除。。。。
发表于 2017-07-15 16:13:18 回复(0)
const void 等价于 void const
发表于 2019-01-12 09:54:50 回复(0)

记住就好:

int print(int i ) const; // function print is const
int print(const int i); //argument is const

int n;
const int * pc = &n; // pc is a non-const pointer to a const int
// *pc = 2; // Error: n cannot be changed through p without a cast
pc = NULL; // OK: pc itself can be changed

int * const cp = &n; // cp is a const pointer to a non-const int
*cp = 2; // OK to change n through cp
// cp = NULL; // Error: cp itself cannot be changed

int * const * pcp = &cp; // non-const pointer to const pointer to non-const int
发表于 2017-09-26 02:52:05 回复(2)
常成员函数 是不能改变成员变量的,应该是函数后面加const
发表于 2019-08-15 20:52:52 回复(0)
const在后面
发表于 2017-09-23 14:01:08 回复(0)