SFML community forums

Help => Graphics => Topic started by: M74 on January 24, 2018, 08:13:18 pm

Title: (Solved) RectangleShape.contains(...) does not compile for me / VS2017
Post by: M74 on January 24, 2018, 08:13:18 pm
Hi,

please take a look at these 2 functions:

private:
        sf::RectangleShape m_shape;

        bool getIsMouseHover_A(int x, int y)
        {
                sf::FloatRect rect = m_shape.getGlobalBounds();
                return (x >= rect.left && x < rect.left + rect.width && y >= rect.top && y < rect.top + rect.height);
        }

        bool getIsMouseHover_B(int x, int y)
        {
                return (m_shape.getGlobalBounds().contains((float)x, (float)y));
        }
 

While method "_A" works fine the method "_B" does not even compile on my Visual Studio 2017.
The compiler complains about Line #81 in sf::RectInl.
    // Compute the real min and max of the rectangle on both axes
    T minX = std::min(left, static_cast<T>(left + width));
 

What`s the reason for this? Did i miss something?

Regards,
Mathias
Title: Re: RectangleShape.contains(...) does not compile for me / VS2017
Post by: FRex on January 24, 2018, 08:46:24 pm
What's the error message?
Title: Re: RectangleShape.contains(...) does not compile for me / VS2017
Post by: M74 on January 24, 2018, 08:55:58 pm
Hi FRex,

please see the attachet screenshot of Visual Studio 2017. Please excuse, that it`s german version - but i think you`ll get the point.

Regards,
Mathias
Title: Re: RectangleShape.contains(...) does not compile for me / VS2017
Post by: eXpl0it3r on January 24, 2018, 08:59:37 pm
Sounds to me like your Visual Studio version is broken. Have you tried using it?
Title: Re: RectangleShape.contains(...) does not compile for me / VS2017
Post by: M74 on January 24, 2018, 09:01:40 pm
As of yet i never had problems with my installation of VS and using SFML. But of course it really could be a problem here locally on my pc if no one can reproduce this compiler-errors.
Title: Re: RectangleShape.contains(...) does not compile for me / VS2017
Post by: M74 on January 24, 2018, 09:12:39 pm
Now i tried the following combination of _A and _B:

        bool getIsMouseHover_C(int x, int y)
        {
                sf::FloatRect rect = m_shape.getGlobalBounds();
                return rect.contains(sf::Vector2f((float)x, (float)y));
        }
 

But also here i get errors on ".contains". Strange, eh...?  ;D
Title: Re: RectangleShape.contains(...) does not compile for me / VS2017
Post by: FRex on January 24, 2018, 09:13:31 pm
This is sketchy AF... ??? Try using std::min and std::max in own code. Did you include Windows.h somewhere?
Title: Re: RectangleShape.contains(...) does not compile for me / VS2017
Post by: M74 on January 24, 2018, 09:18:32 pm
Mh okay. But where do i have to use std::min/max? I thought that this code-example is as simple as it could be xD You are absolutely right, i use Windows Header in my project!
Title: Re: RectangleShape.contains(...) does not compile for me / VS2017
Post by: FRex on January 24, 2018, 09:21:34 pm
Well duh... really, that one? Windows.h (the Windows from Microsoft OS WinApi header, not the SFML/Window.hpp one, that one is fine) has min and max macros that crap up the std:: stuff in C++: https://stackoverflow.com/questions/11544073/how-do-i-deal-with-the-max-macro-in-windows-h-colliding-with-max-in-std
Title: Re: RectangleShape.contains(...) does not compile for me / VS2017
Post by: M74 on January 24, 2018, 09:34:31 pm
Ahhh, thank you! That`s the problem!