简体   繁体   English

uninit_member:非静态类成员m_wszParams不在此构造函数或其在C ++中调用的任何函数中初始化

[英]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.

相关问题 uninit_member:非静态类成员字段m_cJobState.bstatus不在此构造方法或其调用的任何函数中初始化 - uninit_member: Non-static class member field m_cJobState.bstatus is not initialized in this constructor nor in any functions that it calls 没有构造函数的类中的C ++非静态const成员 - C++ non-static const member in class without a constructor 为什么C ++中的函数重载解析将静态调用的非静态成员函数考虑在内? - Why does function overload resolution in C++ consider non-static member functions for static calls? C ++非静态成员函数的开销 - C++ Non-static member functions overhead 实现在C ++中向其注册非静态成员函数的工厂 - implementing a factory that registers non-static member functions to it in C++ c ++指向非静态成员函数的指针 - c++ pointer to non-static member functions 指向模板类的非静态成员函数的C ++函数指针(类成员) - C++ function pointer (class member) to non-static member function of a template class 初始化类的非静态成员变量在哪里? - where are the non-static member variables of a class initialized? 父类“无效使用非静态数据成员”的访问成员C ++ - Accessing member of parent class “Invalid use of non-static data member” C++ C ++函数指针(类成员)到非静态成员函数 - C++ function pointer (class member) to non-static member function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM