Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning C26812: Enum type is unscoped. Prefer enum class over enum

It is puzzling me as to why am I getting this warning at all. I do not even have enumerations in my entire code?

#include <SFML/Graphics.hpp>
#include <vector>

using sf::RenderWindow;
using sf::VideoMode;
using sf::Event;
using std::vector;
using sf::Vector2f;
using sf::RectangleShape;
using sf::CircleShape;
using sf::Color;
using sf::Keyboard;

int main()
{
    RenderWindow window(VideoMode(720, 640), "Shooter game w Projectiles.");
    window.setFramerateLimit(60);

    CircleShape player(50.f);
    player.setFillColor(Color::White);
    player.setPosition((window.getSize().x / 2.f) - (player.getRadius()), (window.getSize().y - player.getRadius() * 2) - 10.f);

    CircleShape bullet(5.f);
    bullet.setFillColor(Color::Red);

    vector<CircleShape> playerBullets;
    playerBullets.push_back(bullet);

    RectangleShape enemy(Vector2f(30.f, 30.f));
    enemy.setFillColor(Color::Magenta);
    enemy.setPosition(320, 200);

    vector<RectangleShape> enemies;
    enemies.push_back(enemy);

    enemy.setFillColor(Color::Blue);
    enemy.setPosition(160, 100);
    enemies.push_back(enemy);

    while (window.isOpen())
    {
        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
            {
                window.close();
            }
        }

        if (Keyboard::isKeyPressed(Keyboard::Escape))
        {
            window.close();
        }

        // Update
        Vector2f playerCenter = Vector2f(player.getPosition().x + player.getRadius(), player.getPosition().y + player.getRadius());

        // Clear
        window.clear();

        // Draw
        window.draw(player);
        for (size_t i = 0; i < enemies.size(); ++i)
        {
            window.draw(enemies[i]);
        }

        for (size_t i = 0; i < playerBullets.size(); ++i)
        {
            window.draw(playerBullets[i]);
        }
        

        // Display
        window.display();
    }
}

This is the warning that I get: The enum type 'sf::PrimitiveType' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).
It warns me on line number 79, which basically is the new line after the main function closing bracket?

like image 860
Programming Rage Avatar asked Aug 27 '20 06:08

Programming Rage


1 Answers

Unfortunately, this warning comes from the header file SFML\Graphics.hpp and the only option is to contact the SFML developers and ask them to fix this warning as suggested by @spectras in the comment section.

There is no solution that I can implement that will solve the warning. However, it is best to disable all the warnings coming from this third party header file by encapsulating it within two pragma statements:

#pragma warning(push, 0)
#include <SFML/Graphics.hpp>
#pragma warning(pop)

With thanks to @Thrasher for providing me with the link in the comment section. Here, is the link:
https://blog.bytellect.com/software-development/c-cplusplus/disabling-warnings-from-legacy-and-third-party-header-files/

like image 121
Programming Rage Avatar answered Sep 24 '22 19:09

Programming Rage