如何在Visual Studio 2019中修复“ [是vulkan结构的成员变量]未初始化。始终初始化成员变量”?

时间:2019-07-02 17:24:21

标签: c++ visual-studio-2019

我从Visual Studio 2017切换到2019,遇到一个警告,说我没来过。如果我有未在默认构造函数中初始化的Vulkan型成员变量(即VkCommandPool,VkBuffer等),则会收到问题标题中列出的警告。

我尝试放入

之类的语句
this->buffer = {};

this->buffer = 0;

但似乎什么都没做。

示例类:

class Example {
    private:
       VkBuffer buffer;
    public:
       // warning comes from here
       Example() {
           // NOTE: even with initialization in the constructor, I STILL get a warning 
           this->buffer = 0;
           this->buffer = {};
       }

       // calls init with parameters
       Example(/* parameters */) {
         // implementation not relevant to the question
       }
       void init(/* parameters */) {
         // implementation not relevant to the question
       }
};

1 个答案:

答案 0 :(得分:1)

进一步的测试表明,我机器上的智能感知有些挑剔,需要一段时间才能更新。重新启动Visual Studio并进行完整的Clean +重建后,似乎可以在构造函数标头中初始化Vulkan变量:

Example() : buffer() { }
函数主体中的

OR:

Example() : { 
    this->buffer = {};
}