SFML community forums

Help => Graphics => Topic started by: JordyD on July 24, 2009, 05:10:06 pm

Title: error: cannot convert 'const float' to 'sf::Rect<float>
Post by: JordyD 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
Title: error: cannot convert 'const float' to 'sf::Rect<float>
Post by: Laurent 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;
}
Title: error: cannot convert 'const float' to 'sf::Rect<float>
Post by: JordyD 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?
Title: error: cannot convert 'const float' to 'sf::Rect<float>
Post by: Laurent 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 ;)
Title: error: cannot convert 'const float' to 'sf::Rect<float>
Post by: JordyD 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.