0

I switched over from Visual Studio 2017 to 2019 and I encountered a warning that I wasn't getting before. If I have a Vulkan-type member variable (i.e. VkCommandPool, VkBuffer, etc.) that is not initialized in the default constructor, I get the warning that is listed in my question title.

I've tried putting statements like

this->buffer = {};

or

this->buffer = 0;

but neither seem to do anything.

Example class:

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
       }
};
yswanderer
  • 202
  • 4
  • 14
  • Show the constructor definitions. – Vlad from Moscow Jul 02 '19 at 17:25
  • Initialize the variable in the constructor's initializer list (see [What is this weird colon-member (“ : ”) syntax in the constructor?](https://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor)). – πάντα ῥεῖ Jul 02 '19 at 17:27
  • What is a `VkBuffer`? – Kevin Jul 02 '19 at 17:27
  • @Kevin OP had a [tag:vulkan] tag before, but that's probably quite irrelevant for the problem. – πάντα ῥεῖ Jul 02 '19 at 17:29
  • 1
    Your initialization probably should happen in your constructor for your `Example` class. `Example() : buffer{} {}` would probably work. – drescherjm Jul 02 '19 at 17:31
  • @πάνταῥεῖ I believe the vulkan tag IS relevant to the question. I have edited my sample code to more accurately describe the problem. I am fully aware that the error is because VkBuffer is not getting initialized in the constructor. The question is HOW do I initialize it with an empty value? – yswanderer Jul 02 '19 at 18:57
  • @dan _"The question is HOW do I initialize it with an empty value?"_ Does `VkBuffer` allow to initialize with a default constructor at all? If not, you have to use the constructors initializer list of your class, there's no way to do that in the constructors body. Quite common and basic stuff, I don't see the specific relation to [tag:vulcan]. – πάντα ῥεῖ Jul 02 '19 at 19:01
  • @drescherjm your solution seems to work. Can you write it as an answer or should I? – yswanderer Jul 02 '19 at 19:01
  • 1
    You can write it as an answer and get the reputation gain. I don't mind. – drescherjm Jul 02 '19 at 19:03
  • Actually, after messing around with it more, it seems to be an issue with Visual Studio 2019's intellisense or with my installation of it (seems odd since it's a fresh install though). drescherjm's solution works sometimes... and sometimes it doesn't. Warnings take a good 10 seconds to refresh, and sometimes they don't without a full rebuild. After my last full rebuild, I no longer have any of the warnings despite some of the variables clearly being uninitialized. I can't find any consistent pattern to it – yswanderer Jul 02 '19 at 19:22
  • I have not seen this behavior however I can tell you that Intellisense is never 100% accurate. – drescherjm Jul 02 '19 at 19:29

1 Answers1

1

Further testing has shown that the intellisense on my machine is being slightly finicky and taking awhile to update. After restarting Visual Studio and doing a full clean + rebuild, it seems that the Vulkan variables can be initialized in the constructor header:

Example() : buffer() { }

OR in the function body:

Example() : { 
    this->buffer = {};
}
yswanderer
  • 202
  • 4
  • 14