Issues with VkRsult?

Hi this might be a super noob question, since I’m learning c++ along with learning Vulkan, so this issue might be a c++ setup but today when I booted my PC after the windows update, opening the project that worked with no issues just yesterday, now give me this error.

image

Since I’m following a tutorial, I opened the guy’s code from GitHub and still got the same error.

Hey there,

good question!
Vulkan is a C-style API, which means enums are implemented in a C-style way, which means “unscoped”. This error means VkResult in Vulkan header files should be declared like this:

enum class VkResult; (scoped enum)

instead of

enum VkResult; (unscoped enum)

In modern C++, you should prefer scoped enums over unscoped enums. So this is not an error, it’s a warning. I guess you get an error because you enabled an option in your settings which sees warnings as errors? You can change this in Visual Studio settings:

Configuration Properties -> C/C++ -> General -> Treat Warning As Errors

It’s not your fault because it’s an issue with Vulkan header files. However, Vulkan API is a C-style API and is not written in modern C++ (C++11, C++14, C++17 or C++20…).

You should not worry too much about this warning. The major advantage of using enum class VkResult would be that “namespace pollution” would be avoided. Another argument is the improved type-safety.

You can read more about this in the official C++ core guidelines:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-class

Or in Scott Meyers book “Effective modern C++”
It’s a book for advanced programmers though.

As a general note, I really recommend to learn modern C++ by reading the C++ core guidelines. They are crafted by a community of world leading C++ experts and really state how C++ should be used. But again, it’s not an issue which comes from the code you wrote.

best regards
Johannes

1 Like

Ah I see,
in the end it was indeed me being a noob at it.
I poked a bit in to this and found that the problem was not in the VkResult but I was requesting a device extension that required an instance extension that I didn’t provided. And the VkResult was giving me the error so I assumed the squiggly line was telling me there is something wrong with my declaration.
It’s odd because everything worked fine yesterday…And today all of a sudden it didn’t but at least now I know. And I got some useful links, thanks @IAmNotHanni

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.