[英]uninit_member: Non-static class member m_wszParams is not initialized in this constructor nor in any functions that it calls in C++
I have IVerification class and this class has two member variables (m_wszParams and m_wszParamType). 我有IVerification类,该类有两个成员变量(m_wszParams和m_wszParamType)。 Here in this class constructor, I am not initializing these member variables.
在此类构造函数中,我没有初始化这些成员变量。 Later, initializing these variables in the derived class(MyReader).
稍后,在派生类(MyReader)中初始化这些变量。
Because of this I am getting the warning "uninit_member: Non-static class member m_wszParams is not initialized in this constructor nor in any functions that it calls." 因此,我收到警告“ uninit_member:非静态类成员m_wszParams不在此构造函数中或在其调用的任何函数中初始化”。
To resolve this warning, can I initialize these member variables with nullptr in the IVerification constructor like as shown below? 要解决此警告,是否可以在IVerification构造函数中使用nullptr初始化这些成员变量,如下所示?
IVerification::IVerification()
{
m_wszParams = nullptr;
m_wszParamType = nullptr;
}
Below is the complete code: 以下是完整的代码:
.h file .h文件
class IVerification
{
public:
IVerification();
virtual ~IVerification();
protected:
wchar_t* m_wszParams;
wchar_t* m_wszParamType;
}
.cpp file .cpp文件
IVerification::IVerification()
{
}
Below is the derived class 下面是派生类
MyReader.h file MyReader.h文件
class MyReader : public IVerification
{
public:
MyReader();
~MyReader();
public:
void SetParams(wchar_t* wszParams, wchar_t* wszParamType);
}
MyReader.cpp file MyReader.cpp文件
void MyReader::SetParams(wchar_t* wszParams, wchar_t* wszParamType)
{
m_wszParamType = wszParamType;
m_wszParams = wszParams;
}
At a minimum 最低限度
class IVerification { public: IVerification()= default; virtual ~IVerification()
= default; protected: wchar_t* m_wszParams
= nullptr; wchar_t* m_wszParamType
= nullptr; };
Next step: pointers are not your friends, use std::string. 下一步:指针不是您的朋友,请使用std :: string。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.