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

Author Topic: error: cannot convert 'const float' to 'sf::Rect<float>  (Read 3918 times)

0 Members and 1 Guest are viewing this topic.

JordyD

  • Newbie
  • *
  • Posts: 10
    • View Profile
error: cannot convert 'const float' to 'sf::Rect<float>
« on: July 24, 2009, 05:10:06 pm »
I'm getting two errors when trying to compile this function:

Code: [Select]
sf::Rect<float>* DeriveRect(sf::Shape* shape)
{
    sf::Rect<float>* rect(shape->GetPointPosition(0).x,
                          shape->GetPointPosition(0).y,
                          shape->GetPointPosition(3).x,
                          shape->GetPointPosition(3).y); /* The errors bring me to this line */
    return rect;
}


The errors:
Code: [Select]
error: initializer expression list treated as compound expression
error: cannot convert 'const float' to 'sf::Rect<float>*' in initialization


I get the feeling that these are simple errors, but I could be wrong.

More information:
OS: Mac OS X 10.5
Compiler: g++
IDE: XCode 3
I have not called this function anywhere in the other parts of the program yet.
This is my first time with SFML.

Could anybody help me out with this?

Thanks,
Jordy

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
error: cannot convert 'const float' to 'sf::Rect<float>
« Reply #1 on: July 24, 2009, 05:22:22 pm »
Forget about pointers
Code: [Select]
sf::Rect<float> DeriveRect(sf::Shape* shape)
{
    sf::Rect<float> rect(shape->GetPointPosition(0).x,
                          shape->GetPointPosition(0).y,
                          shape->GetPointPosition(3).x,
                          shape->GetPointPosition(3).y); /* The errors bring me to this line */
    return rect;
}
Laurent Gomila - SFML developer

JordyD

  • Newbie
  • *
  • Posts: 10
    • View Profile
error: cannot convert 'const float' to 'sf::Rect<float>
« Reply #2 on: July 24, 2009, 05:26:03 pm »
Quote from: "Laurent"
Forget about pointers
Code: [Select]
sf::Rect<float> DeriveRect(sf::Shape* shape)
{
    sf::Rect<float> rect(shape->GetPointPosition(0).x,
                          shape->GetPointPosition(0).y,
                          shape->GetPointPosition(3).x,
                          shape->GetPointPosition(3).y); /* The errors bring me to this line */
    return rect;
}


Doesn't that mean I have to pass around an entire sf::Rect? Isn't that slow?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
error: cannot convert 'const float' to 'sf::Rect<float>
« Reply #3 on: July 24, 2009, 05:38:21 pm »
No, that's just copying 4 floats. And to properly return a pointer, you would have to allocate it using new, and make the caller delete it. Which is ugly ;)
Laurent Gomila - SFML developer

JordyD

  • Newbie
  • *
  • Posts: 10
    • View Profile
error: cannot convert 'const float' to 'sf::Rect<float>
« Reply #4 on: July 24, 2009, 05:39:48 pm »
Quote from: "Laurent"
No, that's just copying 4 floats. And to properly return a pointer, you would have to allocate it using new, and make the caller delete it. Which is ugly ;)


Ah, OK. Thanks. Besides some logic errors, it seems to be working now.