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

Author Topic: Why is my class not drawn?  (Read 1809 times)

0 Members and 1 Guest are viewing this topic.

kingcools

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Why is my class not drawn?
« on: July 03, 2012, 06:29:45 pm »
Hello,

i got the following class:

class abc
:public sf::drawable,public error
{
public:
//something
void draw(blabla)const;
}

as you can see the class abc inheris from sf::drawable and error. The class error does not have a draw function(and it's no class that should be drawn, it just does some errormanagement), but when i inherit from the error class, abc stops getting drawn(which it correctly is, if i do not inherit from the error class).

So what do i do to change this? Does my error class have to inherit from sf::drawable as well? oO

Hmm, guess i should just add that error class as a member instead of inheriting...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
Re: Why is my class not drawn?
« Reply #1 on: July 03, 2012, 06:58:21 pm »
It has to be something in your code, because the following minimal example works fine with me...

#include <SFML/Graphics.hpp>

class Foo
{
public:
        Foo() {}
};

class Bar : public sf::Drawable, public Foo
{
public:
        Bar() : Drawable(), Foo(), mRect(sf::Vector2f(10, 10)) {}
        void draw(sf::RenderTarget &target, sf::RenderStates states) const { target.draw(mRect, states); }

private:
        sf::RectangleShape mRect;
};

int main()
{
        sf::RenderWindow window(sf::VideoMode(1024, 768), "Hello");
        Bar test;

        while(window.isOpen())
        {
                test.draw(window, sf::RenderStates::Default);
       
                window.display();
        }


        return 0;
}
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

kingcools

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Why is my class not drawn?
« Reply #2 on: July 03, 2012, 10:02:41 pm »
ok, thank you, i will look further into it

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Why is my class not drawn?
« Reply #3 on: July 06, 2012, 03:41:55 am »
Hmm, guess i should just add that error class as a member instead of inheriting...
I think I'd recommend this... why on earth are you inheriting from error anyway?

kingcools

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Why is my class not drawn?
« Reply #4 on: July 07, 2012, 05:49:17 am »
to give my class an error log ability ;)