SFML community forums
Help => Graphics => Topic started by: JordyD on July 24, 2009, 05:10:06 pm
-
I'm getting two errors when trying to compile this function:
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:
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
-
Forget about pointers
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;
}
-
Forget about pointers
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?
-
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 ;)
-
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.