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

Author Topic: Problem with inheritance from Drawable  (Read 3552 times)

0 Members and 1 Guest are viewing this topic.

cristaloleg

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Problem with inheritance from Drawable
« on: October 04, 2012, 09:03:31 pm »
I'm trying to create this class from Drawable, but I get:

error C2259: 'Triangle' : cannot instantiate abstract class in Visual Studio 2008
I'm using sfml 1.6
This is my code. Thank's for any help.


class Triangle : public sf :: Drawable
{
public:
        Triangle () { };
        Triangle ( sf::Vector2f Pos, sf::Vector2f Scale, float Rotation, sf::Color Color ) { };
        ~Triangle () { };
        void Render ( sf :: RenderTarget& Target ) { };
};
 
« Last Edit: October 05, 2012, 07:49:58 am by cristaloleg »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Problem with inheritance from Drawable
« Reply #1 on: October 04, 2012, 09:37:04 pm »
How this fits in C forum is beyond me..
Render should have virtual in front of void.
D-tor too but it's less important and doesn't stop program from compiling.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with inheritance from Drawable
« Reply #2 on: October 04, 2012, 09:58:03 pm »
Have a look at the sf::Drawable class and use the exact same prototype for Render.

Quote
Render should have virtual in front of void.
It is optional, it wouldn't change anything. A function declared virtual in a base class is implicitely virtual in derived classes.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Problem with inheritance from Drawable
« Reply #3 on: October 04, 2012, 11:30:25 pm »
I never realized that. ;D
Since you gotta redeclare so there is no jumping across bases to find if function exists or not I assumed virtual is supposed to be there..
Well, op is missing const then. :)
Back to C++ gamedev with SFML in May 2023

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Problem with inheritance from Drawable
« Reply #4 on: October 04, 2012, 11:45:19 pm »
Render should have virtual in front of void.
It is not required, but good practice to see directly (without base class lookup) if a function is virtual.

D-tor too but it's less important and doesn't stop program from compiling.
The destructor should not even be declared here, since it is empty (and virtual anyway).

Furthermore, cristaloleg might decide if he prefers spaces around the scope operator or not ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

cristaloleg

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: Problem with inheritance from Drawable
« Reply #5 on: October 05, 2012, 07:54:10 am »
Thank's for everybody, but I'm still getting compilation error.

Have a look at the sf::Drawable class and use the exact same prototype for Render.

In SFML-1.6 Drawable.hpp
virtual void Render(RenderTarget& Target) const = 0;

So I write in my code(redeclaring virtual function Render)
void Render ( sf :: RenderTarget& Target ) { };

But I don't understand where is error. Can You provide some code for me?
Thank's

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with inheritance from Drawable
« Reply #6 on: October 05, 2012, 08:17:06 am »
Don't you see that const in the prototype?
Laurent Gomila - SFML developer

cristaloleg

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: Problem with inheritance from Drawable
« Reply #7 on: October 05, 2012, 01:17:02 pm »
Don't you see that const in the prototype?

Unbelievable! I never used code like this. Thank's You very much for everybody.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Problem with inheritance from Drawable
« Reply #8 on: October 05, 2012, 01:28:27 pm »
Unbelievable! I never used code like this.
The const says that the method doesn't change the object.

I recommend to work with it, too, const-correctness is a very powerful concept. Read the corresponding chapter of your C++ book ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: