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

Author Topic: How to destroy a class object (destroy all data of this object)  (Read 2274 times)

0 Members and 1 Guest are viewing this topic.

wardi2331

  • Newbie
  • *
  • Posts: 1
    • View Profile
How to destroy a class object (destroy all data of this object)
« on: November 02, 2018, 12:48:53 pm »
hello everybody im asking if there someone can help me ,im working  RPG game and i divise my program to classes as that:
building
actors: inherte from building
houses: inherte from building
platforms: inherte from building
objects: inherte from building

for exemple
class of building:
-----------------------------------------------------------
[color=green]class building
{
public:
    building(float xpos,float ypos, float size_x, float size_y,string file);
        building(void);
        ~building(void);
        void add_texture(string file);
        void position_input(float xpos,float ypos);
        float position_output(string var);
        void scale_input(float width,float height);
        void sprite_cadre(int xh,int yh,int xl,int yl);
        void charger_texture(void);
        void smoothing(void);
        Sprite core(void);
       
protected:
        struct position
        {
                float x;
                float y;
               
        }position;
        struct size
        {  
                 float xsize;
                 float ysize;
        }size;
        struct frame
        {
                int xh;
                int yh;
                int xl;
                int yl;
        }frame;

        string fichier;
        Texture ma_texture;
       
        Sprite ma_sprite;
       
};[/color]
-----------------------------------------------------------------

class of actors
-------------------------------------------
[color=red]class objects;
class actors : public building
{

public:
       
        actors(float posx,float posy,float size_xa,float size_ya,string file_a,unsigned int vitesse);
        actors(void);
        ~actors(void);
        void animation(unsigned int vitesse,bool autonome=false);
        void set_animation(Vector2i anima);
        void moving_core(void);
        void stoping_core(void);
        void colision(objects *the_object,bool contact,int object_type);
        void new_position(int at_x,int at_y);
       
private:
        Vector2i animat;
        Clock time;
        unsigned int Vitesse;
   
        struct last_pos
        {
                 float x_last;
                 float y_last;
        }last_pos;
       
};[/color]
----------------------------------------------------------------

object class :
----------------------------------------------------------------
class objects :
        public building
{
public:
        objects(float posix,float posiy,float sizx,float sizy,string filee);
        objects(void);
        ~objects(void);



};
 
[/color]
------------------------------------------------
in the main :
-----------------------------------
actors my_actor(20,20,1,1,"myactor.png");
objects obj(40,40,1,1,"myobj.png");
my_actor.collision(obj);// i need a methode to destroy object when collision become true
 
[/color]

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Re: How to destroy a class object (destroy all data of this object)
« Reply #1 on: November 03, 2018, 04:03:50 pm »
Parent class must have a virtual destructor.

FYI, asking general, non-sfml related C++ questions is usually discouraged here.

 

anything