SFML community forums

Help => Graphics => Topic started by: Tacostamp on July 05, 2012, 01:15:26 am

Title: Help with creating a derived shape class
Post by: Tacostamp on July 05, 2012, 01:15:26 am
Hi all,

I'm trying to create my own derived shape class in order to make it easier to create hexagons. However, I'm having some trouble with the abstract class sf::Shape. Right now I have:

class Hexagon : public sf::Shape {
public:
        Hexagon(){}
        virtual ~Hexagon();
        virtual int getPointCount() {
                return 6;}
        virtual sf::Vector2f getPoint(unsigned int *index){
                //logic I haven't figured out yet, but I don't think it should matter...
        }
};

Hexagon *newhex;

newhex = new Hexagon();

Problem is, the last line is giving me two errors:

newhex error: This declaration has no storage class or type identifier
Hexagon() error: object of abstract class type "Hexagon" is not allowed.

The Hexagon() error is really confusing since I am using the abstract base sf::Shape and so Hexagon() should no longer be an abstract class. This is my first attempt at abstract base classes so I apologize if I'm doing something wrong that is very obvious.

Thanks for any help!
Title: Re: Help with creating a derived shape class
Post by: eXpl0it3r on July 05, 2012, 04:01:07 am
Why do you just use the sf::ConvexShape (http://www.sfml-dev.org/documentation/2.0/classsf_1_1ConvexShape.php) class? And if you then could create some generate function which will return a convex shape shaped as hexagon?
Title: Re: Help with creating a derived shape class
Post by: Tacostamp on July 05, 2012, 04:37:52 am
I guess I could do that, although I still wish to know why I can't create my own class based on sf::shape ... in SFML 2.0 documentation it seems like they encourage the use of the ability to write your own derived shape class.

Thanks for the idea though! It will do unless I can figure out the answer to my initial question.
Title: Re: Help with creating a derived shape class
Post by: Laurent on July 05, 2012, 08:20:56 am
Check the signature of the getPoint function, yours doesn't match the one in the base class.