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

Author Topic: Custom shape class error  (Read 2637 times)

0 Members and 1 Guest are viewing this topic.

Dajcok

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Custom shape class error
« on: March 31, 2020, 01:28:55 pm »
Hello,
I created custom shape for my project and when I want to call object of this class i get an error: Object of abstract class "dcad::DimensioningLine" is not allowed pure virtual function "sf::Shape::getPoint()" has no overrider.
Here is the code:
#ifndef DCAD_DIMENSIONINGLINE_H
#define DCAD_DIMENSIONINGLINE_H


#include "SFML/Graphics.hpp"

namespace dcad
{
        class DimensioningLine : public sf::Shape
        {
        public:

                explicit DimensioningLine(const sf::Vector2f& size = sf::Vector2f(0, 0)) :
                        m_size(size)
                {
                        update();
                }

                void setSize(const sf::Vector2f& size)
                {
                        m_size = size;
                        update();
                }

                const sf::Vector2f& getSize() const
                {
                        return m_size;
                }

                virtual std::size_t getPointCount() const
                {
                        return 10;
                }

                virtual sf::Vector2f getPoint(unsigned int index) const
                {
                        float x, y;

                        switch (index)
                        {
                        default:
                        case 0: return sf::Vector2f(x, y);
                        case 1: return sf::Vector2f(x + 7, y + 7);
                        case 2: return sf::Vector2f(x + 14, y);
                        case 3: return sf::Vector2f(x + 7, y + 7);
                        case 4: return sf::Vector2f(x + 7, y - 7);
                        case 5: return sf::Vector2f(x + 7 + m_size.x, y);
                        case 6: return sf::Vector2f(x + 7 + m_size.x, y + 7);
                        case 7: return sf::Vector2f(x + m_size.x, y);
                        case 8: return sf::Vector2f(x + 7 + m_size.x, y + 7);
                        case 9: return sf::Vector2f(x + 14 + m_size.x, y);
                        }
                }

        private:

                sf::Vector2f m_size;
        };
}
#endif DCAD_DIMENSIONINGLINE_H
Anyone knows why am I getting this error ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Custom shape class error
« Reply #1 on: March 31, 2020, 04:03:31 pm »
Hi

The message is clear, you don't (correctly) override the getPoint function. How to find the correct prototype? Look at the documentation ;)
Laurent Gomila - SFML developer

randomUser

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Custom shape class error
« Reply #2 on: October 23, 2024, 04:15:26 pm »
I am sorry but can't you just answer the question instead of being so condescending, they might be new to dev and you just don't help, or maybe you help them being insecure about dev. At least send a link to the right documentation page if you want them to look by themselves.

 

anything