什么是const对象和const函数 [英] What is const object and const function
本文介绍了什么是const对象和const函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是const对象和const函数.
What is const object and const functions.
推荐答案
当我将您的问题提交给Google时的第一个结果:
http://www.learncpp.com/cpp-tutorial/810 -const-class-objects-and-member-functions/ [
1st result when I put your question into google:
http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/[^]
我会说:它们是常量实体".
我会添加:请检查文档 [
I would say: "they are constant entities".
I would add: "please, check out the documentation[^]".
const函数:属于类的成员函数,
例如:
const function: belong a class''s member function,
for example:
class CWnd
{
public:
void ConstFunction() const
{
// It's a const function, you can change the member of this pointer.
}
void UnConstFunction()
{
}
}
// It's a const object, you can't change the member of wnd, you can't call the un-const function of
// CWnd, such as UnConstFunction.
const CWnd wnd;
添加了代码块[/编辑]
Code block added[/Edit]
这篇关于什么是const对象和const函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文