Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::PrimitiveType is unscoped warning in VS 2k19  (Read 3314 times)

0 Members and 1 Guest are viewing this topic.

Daniel

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
sf::PrimitiveType is unscoped warning in VS 2k19
« on: June 25, 2020, 01:02:30 am »
Hello! I'm currently working on a personal project in Visual Studio 2019. I've created some 'buttons' for a menu and I decided that I want to put them in a container, such as a vector. My issue is that whenever I use this vector to display the buttons, I get this warning: "The enum type 'sf::PrimitiveType' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).". It is not a big issue, but I'd like to get rid of this warning and know the meaning...

Also, I am working with classes... so I don't have everything in one file, I'll put here just the definitions of the main methods.


Interface::Interface()
{
        // A constructor where I am creating the buttons and then append them to a vector of type Button

        if (!font.loadFromFile("/AlgorithmSimulator/design/quicksandBold.otf"))
                std::cerr << "There's no such file" << std::endl;
       
        Button sortingAlgsB("Sorting Algorithms", sf::Color::Black, 15, sf::Color(224, 251, 252), { 200, 50 });
        sortingAlgsB.SetFont(font);
        sortingAlgsB.Positionate({ 100, 100 });

        Button pathAlgsB("Pathfinding Algorithms", sf::Color::Black, 15, sf::Color(224, 251, 252), { 200, 50 });
        pathAlgsB.SetFont(font);
        pathAlgsB.Positionate({ 100, 50 });



        buttons.push_back(sortingAlgsB);
        buttons.push_back(pathAlgsB);

       
        Init();
               
}

void Interface::Init()
{
        // Here's the method with the main loop

        sf::RenderWindow window(sf::VideoMode(1280, 800), "AlgorithmSimulator");
               
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        for (std::vector<Button>::iterator it = buttons.begin(); it != buttons.end(); it = std::next(it))
                        {
                                switch (event.type)
                                {
                                case sf::Event::Closed:
                                        window.close();
                                case sf::Event::MouseMoved:
                                        if ((*it).DetectMouse(window) == true)
                                        {
                                                (*it).SetTextColor(sf::Color(154, 3, 30));
                                        }
                                        else
                                        {
                                                (*it).SetTextColor(sf::Color::Black);
                                        }
                                        break;
                                case sf::Event::MouseButtonPressed:
                                        if ((*it).DetectMouse(window) == true)
                                        {
                                                (*it).SetTextColor(sf::Color::White);
                                                (*it).SetShapeColor(sf::Color(154, 3, 30));
                                        }
                                        break;
                                case sf::Event::MouseButtonReleased:
                                        if ((*it).DetectMouse(window) == true || (*it).DetectMouse(window) == false)
                                        {
                                                (*it).SetTextColor(sf::Color::Black);
                                                (*it).SetShapeColor(sf::Color(224, 251, 252));
                                        }
                                        break;
                                }
                        }
                }
                window.clear(sf::Color(224, 251, 252));
                for (std::vector<Button>::iterator it = buttons.begin(); it != buttons.end(); it = std::next(it))
                {
                        (*it).Draw(window);
                }
                //pathAlgsB.Draw(window);
                window.display();      
        }
}

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: sf::PrimitiveType is unscoped warning in VS 2k19
« Reply #1 on: June 25, 2020, 08:47:33 am »
In C++11 "enum class" was introduced to fix some problems of traditional enums. Type safety and scoped identifiers polluting the global namespace but now has some problems of its own  :P. Here is an example.

SFML was written before C++11 and it still does not uses features of it for backwards compatibility. So you cannot really fix the warning without rewriting SFML, which I do not recommend. Maybe there is a compiler switch to turn off this warning since you now know about "enum classes"  :D


Daniel

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: sf::PrimitiveType is unscoped warning in VS 2k19
« Reply #2 on: June 25, 2020, 02:29:19 pm »
It makes sense now. Thanks for your answer!