Valgrind使用默认参数给变量赋予“未初始化值的条件跳转”

时间:2013-10-11 00:33:03

标签: c++ constructor valgrind

我在一些C ++代码上运行valgrind并且它给出了一个错误,说我对未初始化的值有条件跳转。这是一段有问题的代码,它是一种方法(不是静态的)。

if (debug_ & 0x1) {
    printf("Debugging information...\n");
}

但变量debug_在构造函数中设置如下:

MyClass::MyClass(
    AnotherClass* interface,
    int debug) :
    debug_(debug)
{
    //Some other irrelevant stuff


}

标题定义了该参数的默认参数:

class MyClass : boost::noncopyable {
  public:
    explicit MyClass(AnotherClass* interface, int debug=0xFF);

  //Other stuff
  private:
    int debug_;
}

但是,即使我实例化这个类,我也可以将值传递给第二个参数。我错过了什么?

1 个答案:

答案 0 :(得分:0)

好吧,我觉得愚蠢,但SSCCE的事情指向了正确的方向。我以为我会看一切,但没有。该类中有一个setDebug()方法可以更改调试值,并且构造函数调用它几个级别并从另一个尚未初始化的结构传入数据。