开发者

Finding Uninitialized Member In Visual Studio 2010 Using Code Analysis

开发者 https://www.devze.com 2023-03-13 14:48 出处:网络
I got some members in my class used without being initialized.Unexpectedly, the MSVC++ 2010 compiler doesn\'t complain and code analysis produce no error/warning.It does able to complain about uniniti

I got some members in my class used without being initialized. Unexpectedly, the MSVC++ 2010 compiler doesn't complain and code analysis produce no error/warning. It does able to complain about uninitialized local var or unreference local var only.

What k开发者_如何转开发ind of setup should I do to pickup such errors?


Actually, that is not an error or warning. If class member does not initialized explicitly, it initializes with default initialization (if must be initialized).

records

class f{
std::string m
f():m(){};
};

class f{
std::string m
f(){};
};

doing the same.

If class member has no default constructor, it must be initialized in class constructor, and compiler wil give an error for this.

class A{
public:
   a(int i):m_i(i){};
protected:
  int m_i;
  a(){};
};

class B{
   A m_a;
   B(){}; 
};

This will cause compiler error.

0

精彩评论

暂无评论...
验证码 换一张
取 消