简体   繁体   English

警告 C26812:枚举类型没有作用域。 比枚举更喜欢枚举类

[英]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.这是我得到的警告:枚举类型 'sf::PrimitiveType' 没有作用域。 Prefer 'enum class' over 'enum' (Enum.3).更喜欢“枚举类”而不是“枚举”(Enum.3)。
It warns me on line number 79, which basically is the new line after the main function closing bracket?它在第 79 行警告我,这基本上是主函数右括号后的新行?

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.不幸的是,此警告来自头文件SFML\\Graphics.hpp ,唯一的选择是联系 SFML 开发人员并要求他们按照@spectras 在评论部分的建议修复此警告。

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 语句中来禁用来自该第三方头文件的所有警告:

#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.感谢@Thrasher 在评论部分为我提供链接。 Here, is the link:链接在这里:
https://blog.bytellect.com/software-development/c-cplusplus/disabling-warnings-from-legacy-and-third-party-header-files/ https://blog.bytellect.com/software-development/c-cplusplus/disabling-warnings-from-legacy-and-third-party-header-files/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM