SFML community forums

Help => Graphics => Topic started by: phild on February 10, 2013, 12:00:19 am

Title: build error with sf::Shape
Post by: phild on February 10, 2013, 12:00:19 am
Hi,
I've just started with SFML 2.0 . I.m trying to draw a polygon using the following code

#include <cstdlib>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

using namespace std;

/*
 *
 */
int main(int argc, char** argv) {
    sf::Shape poly;
    return 0;
}

When I build the code I get this error

c:/SFML/SFML2/include/SFML/Graphics/Shape.hpp:246:5: error: 'sf::Shape::Shape()' is protected
main.cpp:19:15: error: within this context
main.cpp:19:15: error: cannot declare variable 'poly' to be of abstract type 'sf::Shape'

What have I missed?

I'm useing Netbeans and Vista.

Any help gratefully received.
Title: Re: build error with sf::Shape
Post by: eXpl0it3r on February 10, 2013, 12:08:25 am
What have I missed?
For the forum post, you're missing code=cpp or code=none tags to format your code properly.

For the problem:
main.cpp:19:15: error: cannot declare variable 'poly' to be of abstract type 'sf::Shape'

And if you don't know what an abstract class is, then you've missed some basic C++ knowledge, which is not a bad thing, since there are good books about C++ (http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), of which you can learn things. :)

Ah and you've probably also missed the documentation. ;)
Quote from: Documentation of sf::Shape (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Shape.php#details)
Base class for textured shapes with outline.

sf::Shape is a drawable class that allows to define and display a custom convex shape on a render target.

It's only an abstract base, it needs to be specialized for concrete types of shapes (circle, rectangle, convex polygon, star, ...).
Title: Re: build error with sf::Shape
Post by: phild on February 10, 2013, 04:50:40 pm
Thanks for your help.
I'm off to study abstract types and hopefully learn a little bit more about c++. A never ending story: ;D