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

Author Topic: (Solved) RectangleShape.contains(...) does not compile for me / VS2017  (Read 6261 times)

0 Members and 1 Guest are viewing this topic.

M74

  • Newbie
  • *
  • Posts: 17
    • View Profile
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
« Last Edit: January 24, 2018, 09:34:47 pm by M74 »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: RectangleShape.contains(...) does not compile for me / VS2017
« Reply #1 on: January 24, 2018, 08:46:24 pm »
What's the error message?
Back to C++ gamedev with SFML in May 2023

M74

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: RectangleShape.contains(...) does not compile for me / VS2017
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: RectangleShape.contains(...) does not compile for me / VS2017
« Reply #3 on: January 24, 2018, 08:59:37 pm »
Sounds to me like your Visual Studio version is broken. Have you tried using it?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

M74

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: RectangleShape.contains(...) does not compile for me / VS2017
« Reply #4 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.

M74

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: RectangleShape.contains(...) does not compile for me / VS2017
« Reply #5 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

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: RectangleShape.contains(...) does not compile for me / VS2017
« Reply #6 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?
Back to C++ gamedev with SFML in May 2023

M74

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: RectangleShape.contains(...) does not compile for me / VS2017
« Reply #7 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!

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: RectangleShape.contains(...) does not compile for me / VS2017
« Reply #8 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
Back to C++ gamedev with SFML in May 2023

M74

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: RectangleShape.contains(...) does not compile for me / VS2017
« Reply #9 on: January 24, 2018, 09:34:31 pm »
Ahhh, thank you! That`s the problem!

 

anything