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

Author Topic: build error with sf::Shape  (Read 2319 times)

0 Members and 1 Guest are viewing this topic.

phild

  • Newbie
  • *
  • Posts: 2
    • View Profile
build error with sf::Shape
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: build error with sf::Shape
« Reply #1 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++, of which you can learn things. :)

Ah and you've probably also missed the documentation. ;)
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, ...).
« Last Edit: February 10, 2013, 12:14:37 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

phild

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: build error with sf::Shape
« Reply #2 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