Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 773843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:01:52+00:00 2026-05-14T19:01:52+00:00

I have a level class and a Enemy_control class that is based off an

  • 0

I have a level class and a Enemy_control class that is based off an vector that takes in Enemys as values.
in my level constructor I have:

Enemy tmp( 1200 );
enemys.Add_enemy( tmp ); // this adds tmp to the vector in Enemy_control

enemys being a variable of type Enemy_control. My program crashes after these statements complaining about some destructor problem in level and enemy_control and enemy.

Level1::Level1() : Levels()
{
bgX1 = -60; // -60
bgX2 = -130; // -110
bgX3 = -240; // -
bgY=0; // is this used anymore?

// characterY=330;
max_right_movement=500;
max_left_movement=300;

 // More test
jump_max = 110;
player_current_y = 340;
jump_spd = 4;
player_current_floor_y = 340;
//CONST_LEVEL1_MAIN_Y = new int( 340 );

scrolling = true;
scrolling_right = true; // this var is in levels

level_alive = true;
restart_level = false;

player_level_x = 300;
player_screen_x = 300;

level_end_point = 1035 * 10;
level_start_point = 0;

// create enemys in the level
Enemy tmp( 1200 );
enemys.Add_enemy( tmp );


//    tmp.Set_enemy( 4600 );
//    enemys.Add_enemy( tmp );
scoreTitle = new MyText(25);
score = new MyText(25);
high_score=0;
//onblock=0;

load( "grafx/level1/clouds.png", "grafx/level1/mountain.png", "grafx/level1/ground.png", "sounds/level1music.ogg" );
}

and enemy.h:

/* Enemy.h
* obg
* 1-13-10
*/

#ifndef ENEMY_H
#define ENEMY_H

#include "Character.h"
#include <vector>

class Enemy : public Character
{
    private:
        int enemy_speed,
            DRAW_X,
            spawn_x,
            distance_to_enemy,
            frame_left,
            frame_right,
            death_frame_x,
            death_frame_y;

        int bullet_fire_rate;

        bool following_player;

    private:
        void Draw_enemy_going_right( SDL_Surface *video_surface );
        void Draw_enemy_going_left( SDL_Surface *video_surface );
        void Draw_death( int bgX3, int y, SDL_Surface *video_surface );

        void Move_frame_left();
        void Move_frame_right();

        void Draw_me( int bgX3, int y, SDL_Surface *video_surface, int player_level_x, int player_screen_x );

        void Fire_bullet();

    public:
        Enemy( int spawn_x );
        ~Enemy();

        //void Set_enemy( int spawn_x );
        void Draw( int bgX3, int y, SDL_Surface *video_surface, int player_level_x, int player_screen_x );
        bool Following_player();

};

class Enemy_control
{
    private:
        vector< Enemy > enemy_vector; // change this to a vector

    public:
        Enemy_control();
        ~Enemy_control();

        void Add_enemy( Enemy a_enemy );
        void Draw( int bgX3, int y, SDL_Surface *video_surface, int player_level_x, int player_screen_x );
        //void Free_list_from_memory();
};

Enemy constructor:

Enemy::Enemy( int spawn_x ) : Character()
{

character_image.load( “grafx/enemy1.gif” );

health = 400;
damage = 20;

DRAW_X = spawn_x;
this->spawn_x = spawn_x;

distance_to_enemy = 230;
enemy_speed = 3;
frame_left = 0;
frame_right = 0;
death_frame_x = 390;
death_frame_y = 0;

following_player = false;
bullet_fire_rate = 0;

sprite_info.w = 63;
sprite_info.h = 74;
cout << "enemy built please call Set_enemy()\n";

}

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:01:53+00:00Added an answer on May 14, 2026 at 7:01 pm

    As alread pointed out the description of your problem is not really precise. One of the things which strikes me as odd is why the destructor of any of your classes gets called. Looking at your code it becomes clear that Enemy tmp is a local instance which gets cleaned up after leaving the Level constructor. The Add_Enemy() function receives a copy of this local object. Since you provide no copy constructor the call to character_image.load( "grafx/enemy1.gif" ); will not be executed within the copy constructor and therefor the Enemy objects you store will have no image.

    Maybe you should consider something like this:

    Enemy* tmp = new Enemy( 1200 ); // dynamic allocation of Enemy
    enemey.Add_enemy( tmp );       
    

    If you do someting like this you need to change your vector to store pointers to Enemy objects
    like std::vector< Enemy* > enemies. Do not forget to delete the dynamically allocated objects within the destructor of Enemy_control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object of class Level that has several subsystems (child objects) it
(programming in iPhone objective-C) I have a class level NSString* that I create, add
In subsystem design, I sometimes see software designs that have one high-level class that
I have a high level controller class that is in charge of managing several
I have a class level price variable decalred inside a page, like this: public
On the class level, I have created reference: System::Data::Odbc::OdbcConnection Connection; in some method I
WorkAround: I have declared a class level Public static variable and initialized with a
I have this reqular ul > li structure <ul class='compare'> <li>Level 1 <ul> <li>Level
I have a class with a static std::map member variable that maps char s
I currently have an app on the market that supports Android 1.5 (SDK level

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.