警告 C26812:枚举类型没有作用域.比枚举更喜欢枚举类 [英] Warning C26812: Enum type is unscoped. Prefer enum class over enum

查看:1122
本文介绍了警告 C26812:枚举类型没有作用域.比枚举更喜欢枚举类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

令我困惑的是为什么我会收到此警告.我的整个代码中都没有枚举?

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();
    }
}

这是我得到的警告:枚举类型 'sf::PrimitiveType' 没有作用域.更喜欢枚举类"而不是枚举"(Enum.3).
它在第 79 行警告我,这基本上是主函数右括号后的新行?

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?

推荐答案

不幸的是,此警告来自头文件 SFML\Graphics.hpp,唯一的选择是联系 SFML 开发人员并询问他们按照@spectras 在评论部分的建议修复此警告.

没有我可以实施的解决方案来解决警告.但是,最好通过将其封装在两个 pragma 语句中来禁用来自该第三方头文件的所有警告:

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)

感谢@Thrasher 在评论部分为我提供链接.这是链接:
https://blog.bytellect.com/software-development/c-cplusplus/disabling-warnings-from-legacy-and-third-party-header-files/

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/

这篇关于警告 C26812:枚举类型没有作用域.比枚举更喜欢枚举类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆