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

Author Topic: Help with creating a derived shape class  (Read 1892 times)

0 Members and 1 Guest are viewing this topic.

Tacostamp

  • Newbie
  • *
  • Posts: 7
    • View Profile
Help with creating a derived shape class
« 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!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Help with creating a derived shape class
« Reply #1 on: July 05, 2012, 04:01:07 am »
Why do you just use the sf::ConvexShape class? And if you then could create some generate function which will return a convex shape shaped as hexagon?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tacostamp

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Help with creating a derived shape class
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Help with creating a derived shape class
« Reply #3 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.
Laurent Gomila - SFML developer

 

anything