Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Note:
Enable Microsoft Native Recommended Rules in VS.
I am not initializing data members in constructor/initializer list, instead due to too many data members, these data members are copied within a function and then invoking function from constructor.
Is there any specific reason for this warning message.
warning C26495:
Variable 'Person::m_id' is uninitialized. Always initialize a member variable (type.6).
class Person
std::string m_name;
int m_id;
/* Other data members*/
public:
Person()
initialize();
void initialize()
m_name = "someText";
m_id = 1;
/* Other data members initialization*/
–
–
You get the warning because you don't initialize the member in the constructor or use an initializer list. The fact that you do it in a function call isn't "captured" since it won't check each function call for this simple warnings check. It could quickly become a huge tree of function calls to check.
You probably don't get a warning for your string. This is because when you don't initialize it, it is using its default constructor which constructs an empty string, with a length of zero characters. So your string actually IS initialized. But for basic types like int there is no such default "constructor"
http://www.cplusplus.com/reference/string/string/string/
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.