是否有可能改变const bool值? [英] Is it possible const bool value to be changed?

查看:463
本文介绍了是否有可能改变const bool值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我上课了,我在构造函数中初始化了一个const bool值。

我没有使用任何代码来改变类中的值。

但是在创建一个对象后,它的值会改变。

我检查了编码,但是没有问题。

(在我的项目中,应该使用unicode。)

我不知道原因。
你能给我任何建议吗? ?



我在Windows 8.1中使用visual studio 2013开发C ++程序。



Hi, everyone.

I made a class and I initialize a const bool value in constructor.
And I didn't make any code to change the value in the class.
But after an object is created, its value is changed.
I checked encoding, but there was no problem.
(In my project, unicode should be used.)
I don't have any idea the reason.
Can you give me any advice?

I develop C++ program with visual studio 2013 in Windows 8.1.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// constructor
CCube::CCube( const bool bControlCtrlPts )
    : _bControlCtrlPts( bControlCtrlPts )
{
}

推荐答案

由于指针错误导致内存更改的最常见原因。你必须注意何时发生变化。



调试内存应该有所帮助:如何:设置数据断点。或者你必须编写跟踪代码。
the most common cause of that are memory changes because of errors in pointers. You must watch when the change occurs.

Debugging the memory should help: How to: Set a Data Breakpoint. Or you must write trace code.


只是为了确定:如何声明成员 _bControlCtrlPts



如果是const(这将是无用的),你会得到一个警告:

Just to be sure: How is the member _bControlCtrlPts declared?

If it is const (which would be useless), you would get a warning:
warning C4512: 'CCube' : assignment operator could not be generated





它不是const,成员变量由构造函数设置为传递的值。



It it is not const, the member variable is set by the constructor to the passed value.


这篇关于是否有可能改变const bool值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆