开发者

Finding Uninitialized Member In Visual Studio 2010 Using Code Analysis

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜