SFML community forums
Help => Graphics => Topic started by: danthebeliever on March 24, 2011, 09:28:25 pm
-
Hi.
sf::Shape * genSquare = new sf::Shape::Rectangle(0,0,100,100,sf::Color::Red);
This will not compile for me. I get an "expected type-specifier" error.
Any thoughts?
I need it to be a pointer else it will go out of scope for the other object I am using it for and thus cause a bad access.
EDIT: sf::Shape::Rectangle is not a constructor, it's a static function, so I
need to type it.
The correct code is this:
sf::Shape * genSquare = new sf::Shape(sf::Shape::Rectangle(0,0,100,100,sf::Color::Red));
-
sf::Shape::Rectangle is not a type, it is a static member function. Therefore you must create a sf::Shape dynamically and initialize it with the result of the Rectangle() function.
-
sf::Shape::Rectangle is a static function, not a type name.
sf::Shape * genSquare = new sf::Shape(sf::Shape::Rectangle(0,0,100,100,sf::Color::Red));
-
Great! That works! Thank you very much :)
-
By the way...
I need it to be a pointer else it will go out of scope for the other object I am using it for and thus cause a bad access
You can simply store a copy of it, you probably don't need a pointer to a dynamically allocated instance.
-
Oh gotcha thanks :)
Well I'm using cpGUI and it accepts a pointer for the cpShapeButton. If I pass the address of a statically allocated object it goes out of scope, and since it won't accept an object, I think I do have to allocate it.