jeudi 5 septembre 2019

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). Here in this class constructor, I am not initializing these member variables. Later, initializing these variables in the derived class(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."

To resolve this warning, can I initialize these member variables with nullptr in the IVerification constructor like as shown below?

IVerification::IVerification()
{
    m_wszParams = nullptr;
    m_wszParamType = nullptr;
}

Below is the complete code:

.h file

class IVerification
{

public:
    IVerification();
    virtual ~IVerification(); 

protected:
    wchar_t* m_wszParams;
    wchar_t* m_wszParamType;
}

.cpp file

IVerification::IVerification()
{

}

Below is the derived class

MyReader.h file

class MyReader : public IVerification
{
public:
    MyReader();
    ~MyReader();
public:
    void SetParams(wchar_t* wszParams, wchar_t* wszParamType);
}

MyReader.cpp file

void MyReader::SetParams(wchar_t* wszParams, wchar_t* wszParamType)
{
    m_wszParamType = wszParamType;
    m_wszParams = wszParams;
}

Aucun commentaire:

Enregistrer un commentaire