Delete Function error

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

37 Replies - 6427 Views - Last Post: 06 February 2013 - 06:27 AM Rate Topic: -----

#1 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Delete Function error

Posted 09 January 2013 - 05:42 PM

I have been making a shooter game for fun, and it is not working. I have made few libraries that is of my own. However, it is giving me problemes with the delete function, and if I take them out, I start to have bunch of linker errors that confirms me that delete function is needed...

#include <allegro.h>
#include <cstdlib>
#include <time.h>
#include "Character.h"
#include "Ship.h"
#include "Laser.h"

Ship myShip;
Laser myLaser;
Character myEnemies[10];
Laser enemyLasers[10];

BITMAP* buffer;
BITMAP* ship;
BITMAP* enemy;
BITMAP* laser;
BITMAP* enemyLaser;

bool update = true;

void Draw(){

    acquire_screen();
    draw_sprite( screen, buffer, 0, 0);
    release_screen();

    update = false;
    
    rest(50);

}

void SetRandSeed(){

    time_t secs;
    time(&secs);
    srand( (unsigned int)secs);

}

void updateLives(){

    char tempStr[2];
    itoa(myShip.GetLives(), tempStr, 10);
    textout_ex( buffer, font, tempStr, 70, 460, makecol( 255, 0, 0), makecol( 0, 0, 0));

}

void SetupGame(){
     
    SetRandSeed();
     
    myLaser.SetDead( true, buffer);

    for( int i= 0; i <=9; i++){
        if( i < 5)
            myEnemies[i].SetY( 20, buffer, enemy);
        else
            myEnemies[i].SetY( 40, buffer, enemy);
        if( i < 5)
            myEnemies[i].SetX( ((20* i) + 240), buffer, enemy);
        else
            myEnemies[i].SetX( ((20* (i - 5)) + 240), buffer, enemy);
    }
    
    for( int i= 0; i <=9; i++){
    
        enemyLasers[i].SetDead(true, buffer);
    
    }
    
    myShip.SetX( ((640/2) - 40), buffer, ship);
    myShip.SetY( (480 - 40), buffer, ship);
    myShip.SetLives( 4);
    textout_ex( buffer, font, "Lives: ", 10, 460, makecol( 255, 0, 0), makecol( 0, 0, 0));
    updateLives();

    
    Draw();
       

}

void movePlayer(){

    if( key[KEY_RIGHT]){
    
        myShip.SetX( (myShip.GetX() + 20), buffer, ship);
        update = true;
        
    } else if( key[KEY_LEFT]){
    
        myShip.SetX( (myShip.GetX() - 20), buffer, ship);
        update = true;
        
    } else if( key[KEY_SPACE]){
    
        if( myLaser.IsDead()){
        
            myLaser.SetDead(false, buffer);
            myLaser.SetX( myShip.GetX(), buffer, laser);
            myLaser.SetY( (myShip.GetY() - 20), buffer, laser);
            update = true;
        
        }
    
    }

}

void moveLaser(){

    if( !(myLaser.IsDead()) ){
    
        myLaser.SetY( (myLaser.GetY() - 20), buffer, laser);
        
        myLaser.CheckCollision(myEnemies, buffer);
        
        update = true;
        
    }

}

void moveEnemy(){

    int shoot;

    for( int i = 0; i <= 9; i++){
    
        if(!myEnemies[i].IsDead()){
        
            shoot = rand() % 1000 + 1;
            
            if( shoot == 25){
            
                enemyLasers[i].SetDead( false, buffer);
                enemyLasers[i].SetX( myEnemies[i].GetX(),buffer, enemyLaser);
                enemyLasers[i].SetY( 60, buffer, enemyLaser);
                update = true;
            
            }
        
        }
    
    }

}

void moveEnemyLaser(){

    for( int i = 0; i <= 9; i++){
    
        if( !enemyLasers[i].IsDead()){
        
            enemyLasers[i].SetY( (enemyLasers[i].GetY() + 20), buffer, enemyLaser);
            if( (enemyLasers[i].CheckCollision(myShip, buffer))){
            
                myShip.SetLives(myShip.GetLives() - 1);
                updateLives();
                
                
            }
            update = true;
        
        }
    
    }

}

bool checkPlayerLives(){

    if ( myShip.GetLives() <= 0){
         
         textout_ex( screen, font, "GAME OVER", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));
         
         while(!key[KEY_ESC]){}
         
         return true;
    }
    
    return false;

}

bool checkEnemyLives(){

    int enemiesDead = 0;

    for( int i = 0; i <= 9; i++){
    
        if(myEnemies[i].IsDead())
            ++enemiesDead;
    
    }
    
    if(enemiesDead >= 10){
    
        textout_ex( screen, font, "YOU WIN!!!!", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));
        
         while(!key[KEY_ESC]){}
        
         return true;
    }
    
    return false;

}

int main(){

    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
    
    buffer = create_bitmap( 640, 480);
    ship = load_bitmap( "ship.bmp", NULL);
    enemy = load_bitmap( "enemy.bmp", NULL);
    laser = load_bitmap( "laser.bmp", NULL);
    enemyLaser = load_bitmap( "enemyLaser.bmp", NULL);
    
    SetupGame();

    while(!key[KEY_ESC]){
    
        movePlayer();
        moveLaser();
        moveEnemy();
        moveEnemyLaser();
        if(checkPlayerLives())
            break;
        if(checkEnemyLives())
            break;
        
        if(update)
            Draw();
                         
    }

    delete [] myEnemies;
    
    destroy_bitmap( buffer);
    destroy_bitmap( ship);
    destroy_bitmap( enemy);

    return 0;

}
END_OF_MAIN();
 

is what i currently have...

This post has been edited by macosxnerd101: 09 January 2013 - 05:43 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Delete Function error

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Delete Function error

Posted 09 January 2013 - 06:07 PM

Quote

it is not working... it is giving me problemes with the delete function


Please be more specific. What are you trying to achieve, what are the problems and where are they occurring? You mention linker errors and a "delete function", but I'm not sure what you're referring to specifically.
Was This Post Helpful? 0
  • +
  • -

#3 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 09 January 2013 - 06:29 PM

at there, it just says
242
C:\Users\think\Desktop\hw\Untitled4.cpp expected primary-expression before ']' token



 delete [] myEnemies;
243	     
244	    destroy_bitmap( buffer);
245	    destroy_bitmap( ship);
246	    destroy_bitmap( enemy);
247	 
248	    return 0;


so i tried to change to

delete [] myEnemies;
instead, but it has the same problem.

I would be glad if anyone could just tell me how to use delete function. I have googled it, and I cannot find a understandable explation.
Was This Post Helpful? 0
  • +
  • -

#4 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Delete Function error

Posted 09 January 2013 - 06:48 PM

Character myEnemies[10];
delete [] myEnemies;


Using delete is only necessary when you allocate memory with new. 'myEnemies' was not allocated/instantiated using new, so the memory is entirely managed by the compiler (allocation and deletion). I'm not sure what would happen if you try to delete a static array at runtime, although I suspect it would lead to problems and at least a compiler warning/error. The new and delete operators are used to allocate and deallocate memory on the heap at runtime.

Just for clarity...

// allocated and deallocated 'automagically'
int sarr[10];

// needs to be deallocated
int *darr = new int [10];
delete [] darr;

This post has been edited by Aphex19: 09 January 2013 - 07:02 PM

Was This Post Helpful? 0
  • +
  • -

#5 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 09 January 2013 - 06:51 PM

Ohhh.... So if i were to use the New function, would I have to change the most part of the code?
Was This Post Helpful? 0
  • +
  • -

#6 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Delete Function error

Posted 09 January 2013 - 07:09 PM

View Postasasas3354, on 10 January 2013 - 01:51 AM, said:

Ohhh.... So if i were to use the New function, would I have to change the most part of the code?


Probably, but as a general rule, you should avoid allocating memory at runtime unless it's necessary. Even if memory allocation seems appropriate (for example, if you don't know the size of an array at compile time), it's often better to use a container like std::vector which implements a dynamically expanding array without the need to manage the memory yourself.

This post has been edited by Aphex19: 09 January 2013 - 07:14 PM

Was This Post Helpful? 1
  • +
  • -

#7 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 10 January 2013 - 04:28 PM

I am trying to use the new function, so i made this

#include <allegro.h>
#include <cstdlib>
#include <time.h>
#include "Character.h"
#include "Ship.h"
#include "Laser.h"
#include <new>

Character myEnemies[10];

class  Character myEnemies{

public:
   void * operator new[] (10){
   
      return 0;
   }
   void   operator delete[] (void*){
   
   }
};

int main() {

    myEnemies *myEnemies = new  myEnemies[5];
   delete []  myEnemies;
}




but the compiler says

11 C:\Users\think\Desktop\hw\Untitled7.cpp invalid function declaration
C:\Users\think\Desktop\hw\Untitled7.cpp In function `int _mangled_main()':
25 C:\Users\think\Desktop\hw\Untitled7.cpp invalid operands of types `Character[10]' and `Character[10]' to binary `operator*'
25 C:\Users\think\Desktop\hw\Untitled7.cpp `myEnemies' is not a type
26 C:\Users\think\Desktop\hw\Untitled7.cpp [Warning] deleting array `Character myEnemies[10]'

... I am a newbie in programming, so I might have some basic mistakes... I am unsure of what is the problem.
Was This Post Helpful? 0
  • +
  • -

#8 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1329
  • View blog
  • Posts: 4,555
  • Joined: 19-February 09

Re: Delete Function error

Posted 10 January 2013 - 04:55 PM

Something like :

#include <allegro.h>
#include <cstdlib>
#include <time.h>
#include "Character.h"
#include "Ship.h"
#include "Laser.h"
#include <new>


int main() 
{
  // 5 Characters in an array called myEnemies 
  Character *myEnemies = new Character[5];

  delete []  myEnemies;
}





Dynamic Memory
Was This Post Helpful? 1
  • +
  • -

#9 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 10 January 2013 - 05:26 PM

ok, but now I have a Errors that is referring the function as "undefined. This is the code.

#include <allegro.h>
#include <cstdlib>
#include <time.h>
#include "Character.h"
#include "Ship.h"
#include "Laser.h"





Ship myShip;
Laser myLaser;

//Character myEnemies[10];
Laser enemyLasers[10];

BITMAP* buffer;
BITMAP* ship;
BITMAP* enemy;
BITMAP* laser;
BITMAP* enemyLaser;

bool update = true;

void Draw(){

    acquire_screen();
    draw_sprite( screen, buffer, 0, 0);
    release_screen();

    update = false;
    
    rest(50);

}

void SetRandSeed(){

    time_t secs;
    time(&secs);
    srand( (unsigned int)secs);

}

void updateLives(){

    char tempStr[2];
    itoa(myShip.GetLives(), tempStr, 10);
    textout_ex( buffer, font, tempStr, 70, 460, makecol( 255, 0, 0), makecol( 0, 0, 0));

}

void SetupGame(){
     
    SetRandSeed();
     
    myLaser.SetDead( true, buffer);

    for( int i= 0; i <=9; i++){
        if( i < 5)
            myEnemies[i].SetY( 20, buffer, enemy);
        else
            myEnemies[i].SetY( 40, buffer, enemy);
        if( i < 5)
            myEnemies[i].SetX( ((20* i) + 240), buffer, enemy);
        else
            myEnemies[i].SetX( ((20* (i - 5)) + 240), buffer, enemy);
    }
    
    for( int i= 0; i <=9; i++){
    
        enemyLasers[i].SetDead(true, buffer);
    
    }
    
    myShip.SetX( ((640/2) - 40), buffer, ship);
    myShip.SetY( (480 - 40), buffer, ship);
    myShip.SetLives( 4);
    textout_ex( buffer, font, "Lives: ", 10, 460, makecol( 255, 0, 0), makecol( 0, 0, 0));
    updateLives();

    
    Draw();
       

}

void movePlayer(){

    if( key[KEY_RIGHT]){
    
        myShip.SetX( (myShip.GetX() + 20), buffer, ship);
        update = true;
        
    } else if( key[KEY_LEFT]){
    
        myShip.SetX( (myShip.GetX() - 20), buffer, ship);
        update = true;
        
    } else if( key[KEY_SPACE]){
    
        if( myLaser.IsDead()){
        
            myLaser.SetDead(false, buffer);
            myLaser.SetX( myShip.GetX(), buffer, laser);
            myLaser.SetY( (myShip.GetY() - 20), buffer, laser);
            update = true;
        
        }
    
    }

}

void moveLaser(){

    if( !(myLaser.IsDead()) ){
    
        myLaser.SetY( (myLaser.GetY() - 20), buffer, laser);
        
        myLaser.CheckCollision(myEnemies, buffer);
        
        update = true;
        
    }

}

void moveEnemy(){

    int shoot;

    for( int i = 0; i <= 9; i++){
    
        if(!myEnemies[i].IsDead()){
        
            shoot = rand() % 1000 + 1;
            
            if( shoot == 25){
            
                enemyLasers[i].SetDead( false, buffer);
                enemyLasers[i].SetX( myEnemies[i].GetX(),buffer, enemyLaser);
                enemyLasers[i].SetY( 60, buffer, enemyLaser);
                update = true;
            
            }
        
        }
    
    }

}

void moveEnemyLaser(){

    for( int i = 0; i <= 9; i++){
    
        if( !enemyLasers[i].IsDead()){
        
            enemyLasers[i].SetY( (enemyLasers[i].GetY() + 20), buffer, enemyLaser);
            if( (enemyLasers[i].CheckCollision(myShip, buffer))){
            
                myShip.SetLives(myShip.GetLives() - 1);
                updateLives();
                
                
            }
            update = true;
        
        }
    
    }

}

bool checkPlayerLives(){

    if ( myShip.GetLives() <= 0){
         
         textout_ex( screen, font, "GAME OVER", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));
         
         while(!key[KEY_ESC]){}
         
         return true;
    }
    
    return false;

}

bool checkEnemyLives(){

    int enemiesDead = 0;

    for( int i = 0; i <= 9; i++){
    
        if(myEnemies[i].IsDead())
            ++enemiesDead;
    
    }
    
    if(enemiesDead >= 10){
    
        textout_ex( screen, font, "YOU WIN!!!!", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));
        
         while(!key[KEY_ESC]){}
        
         return true;
    }
    
    return false;

}

int main(){
Character *myEnemies = new Character[5];
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
    
    buffer = create_bitmap( 640, 480);
    ship = load_bitmap( "ship.bmp", NULL);
    enemy = load_bitmap( "enemy.bmp", NULL);
    laser = load_bitmap( "laser.bmp", NULL);
    enemyLaser = load_bitmap( "enemyLaser.bmp", NULL);
    
    SetupGame();

    while(!key[KEY_ESC]){
    
        movePlayer();
        moveLaser();
        moveEnemy();
        moveEnemyLaser();
        if(checkPlayerLives())
            break;
        if(checkEnemyLives())
            break;
        
        if(update)
            Draw();
                         
    }

     delete []  myEnemies;
    
    destroy_bitmap( buffer);
    destroy_bitmap( ship);
    destroy_bitmap( enemy);

    return 0;

}
END_OF_MAIN();




and have a lot of errors like

C:\Users\think\Desktop\hw\Untitled4.cpp In function `void SetupGame()':
62 C:\Users\think\Desktop\hw\Untitled4.cpp `myEnemies' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
C:\Users\think\Desktop\hw\Untitled4.cpp In function `void moveLaser()':
122 C:\Users\think\Desktop\hw\Untitled4.cpp `myEnemies' undeclared (first use this function)
C:\Users\think\Desktop\hw\Untitled4.cpp In function `void moveEnemy()':
136 C:\Users\think\Desktop\hw\Untitled4.cpp `myEnemies' undeclared (first use this function)
C:\Users\think\Desktop\hw\Untitled4.cpp In function `bool checkEnemyLives()':
198 C:\Users\think\Desktop\hw\Untitled4.cpp `myEnemies' undeclared (first use this function)
Was This Post Helpful? 0
  • +
  • -

#10 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3548
  • View blog
  • Posts: 10,986
  • Joined: 05-May 12

Re: Delete Function error

Posted 10 January 2013 - 05:55 PM

The error message says it all:

Quote

`myEnemies' undeclared


It's because you are trying to use the variable before you've declared it. Your declaration on line 217 is only useful for the scope of the main() function. The other functions can not peek into another function's scope.
Was This Post Helpful? 0
  • +
  • -

#11 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 11 January 2013 - 04:14 PM

ok i have fixed the declaration problem, and the Delete/New fuction problem. However, just after i finished it, it started to give me new "Linker Errors"

Here is my code

#include <allegro.h>
#include <cstdlib>
#include <time.h>
#include "Character.h"
#include "Ship.h"
#include "Laser.h"


Character *myEnemies = new Character[5];



Ship myShip;
Laser myLaser;


Laser enemyLasers[10];

BITMAP* buffer;
BITMAP* ship;
BITMAP* enemy;
BITMAP* laser;
BITMAP* enemyLaser;

bool update = true;

void Draw(){

    acquire_screen();
    draw_sprite( screen, buffer, 0, 0);
    release_screen();

    update = false;
    
    rest(50);

}

void SetRandSeed(){

    time_t secs;
    time(&secs);
    srand( (unsigned int)secs);

}

void updateLives(){

    char tempStr[2];
    itoa(myShip.GetLives(), tempStr, 10);
    textout_ex( buffer, font, tempStr, 70, 460, makecol( 255, 0, 0), makecol( 0, 0, 0));

}

void SetupGame(){
     
    SetRandSeed();
     
    myLaser.SetDead( true, buffer);

    for( int i= 0; i <=9; i++){
        if( i < 5)
            myEnemies[i].SetY( 20, buffer, enemy);
        else
            myEnemies[i].SetY( 40, buffer, enemy);
        if( i < 5)
            myEnemies[i].SetX( ((20* i) + 240), buffer, enemy);
        else
            myEnemies[i].SetX( ((20* (i - 5)) + 240), buffer, enemy);
    }
    
    for( int i= 0; i <=9; i++){
    
        enemyLasers[i].SetDead(true, buffer);
    
    }
    
    myShip.SetX( ((640/2) - 40), buffer, ship);
    myShip.SetY( (480 - 40), buffer, ship);
    myShip.SetLives( 4);
    textout_ex( buffer, font, "Lives: ", 10, 460, makecol( 255, 0, 0), makecol( 0, 0, 0));
    updateLives();

    
    Draw();
       

}

void movePlayer(){

    if( key[KEY_RIGHT]){
    
        myShip.SetX( (myShip.GetX() + 20), buffer, ship);
        update = true;
        
    } else if( key[KEY_LEFT]){
    
        myShip.SetX( (myShip.GetX() - 20), buffer, ship);
        update = true;
        
    } else if( key[KEY_SPACE]){
    
        if( myLaser.IsDead()){
        
            myLaser.SetDead(false, buffer);
            myLaser.SetX( myShip.GetX(), buffer, laser);
            myLaser.SetY( (myShip.GetY() - 20), buffer, laser);
            update = true;
        
        }
    
    }

}

void moveLaser(){

    if( !(myLaser.IsDead()) ){
    
        myLaser.SetY( (myLaser.GetY() - 20), buffer, laser);
        
        myLaser.CheckCollision(myEnemies, buffer);
        
        update = true;
        
    }

}

void moveEnemy(){

    int shoot;

    for( int i = 0; i <= 9; i++){
    
        if(!myEnemies[i].IsDead()){
        
            shoot = rand() % 1000 + 1;
            
            if( shoot == 25){
            
                enemyLasers[i].SetDead( false, buffer);
                enemyLasers[i].SetX( myEnemies[i].GetX(),buffer, enemyLaser);
                enemyLasers[i].SetY( 60, buffer, enemyLaser);
                update = true;
            
            }
        
        }
    
    }

}

void moveEnemyLaser(){

    for( int i = 0; i <= 9; i++){
    
        if( !enemyLasers[i].IsDead()){
        
            enemyLasers[i].SetY( (enemyLasers[i].GetY() + 20), buffer, enemyLaser);
            if( (enemyLasers[i].CheckCollision(myShip, buffer))){
            
                myShip.SetLives(myShip.GetLives() - 1);
                updateLives();
                
                
            }
            update = true;
        
        }
    
    }

}

bool checkPlayerLives(){

    if ( myShip.GetLives() <= 0){
         
         textout_ex( screen, font, "GAME OVER", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));
         
         while(!key[KEY_ESC]){}
         
         return true;
    }
    
    return false;

}

bool checkEnemyLives(){

    int enemiesDead = 0;

    for( int i = 0; i <= 9; i++){
    
        if(myEnemies[i].IsDead())
            ++enemiesDead;
    
    }
    
    if(enemiesDead >= 10){
    
        textout_ex( screen, font, "YOU WIN!!!!", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));
        
         while(!key[KEY_ESC]){}
        
         return true;
    }
    
    return false;

}

int main(){
Character *myEnemies = new Character[5];
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
    
    buffer = create_bitmap( 640, 480);
    ship = load_bitmap( "ship.bmp", NULL);
    enemy = load_bitmap( "enemy.bmp", NULL);
    laser = load_bitmap( "laser.bmp", NULL);
    enemyLaser = load_bitmap( "enemyLaser.bmp", NULL);
    
    SetupGame();

    while(!key[KEY_ESC]){
    
        movePlayer();
        moveLaser();
        moveEnemy();
        moveEnemyLaser();
        if(checkPlayerLives())
            break;
        if(checkEnemyLives())
            break;
        
        if(update)
            Draw();
                         
    }

     delete []  myEnemies;
    
    destroy_bitmap( buffer);
    destroy_bitmap( ship);
    destroy_bitmap( enemy);

    return 0;

}
END_OF_MAIN();




and here is 43 problems

undefined reference to `Ship::GetLives()'
undefined reference to `Character::SetDead(bool, BITMAP*)'
undefined reference to `Character::SetY(int, BITMAP*, BITMAP*)'
undefined reference to `Character::SetY(int, BITMAP*, BITMAP*)'
undefined reference to `Character::SetX(int, BITMAP*, BITMAP*)'
undefined reference to `Character::SetX(int, BITMAP*, BITMAP*)'
undefined reference to `Character::SetDead(bool, BITMAP*)'
undefined reference to `Character::SetX(int, BITMAP*, BITMAP*)'
undefined reference to `Character::SetY(int, BITMAP*, BITMAP*)'
undefined reference to `Ship::SetLives(int)'
undefined reference to `Character::GetX()'
undefined reference to `Character::SetX(int, BITMAP*, BITMAP*)'
undefined reference to `Character::GetX()'
undefined reference to `Character::SetX(int, BITMAP*, BITMAP*)'
undefined reference to `Character::IsDead()'
undefined reference to `Character::SetDead(bool, BITMAP*)'
undefined reference to `Character::GetX()'
undefined reference to `Character::SetX(int, BITMAP*, BITMAP*)'
undefined reference to `Character::GetY()'
undefined reference to `Character::SetY(int, BITMAP*, BITMAP*)'
undefined reference to `Character::IsDead()'
undefined reference to `Character::GetY()'
undefined reference to `Character::SetY(int, BITMAP*, BITMAP*)'
undefined reference to `Laser::CheckCollision(Character*, BITMAP*)'
undefined reference to `Character::IsDead()'
undefined reference to `Character::SetDead(bool, BITMAP*)'
undefined reference to `Character::GetX()'
undefined reference to `Character::SetX(int, BITMAP*, BITMAP*)'
undefined reference to `Character::SetY(int, BITMAP*, BITMAP*)'
undefined reference to `Character::IsDead()'
undefined reference to `Character::GetY()'
undefined reference to `Character::SetY(int, BITMAP*, BITMAP*)'
undefined reference to `Laser::CheckCollision(Character, BITMAP*)'
undefined reference to `Ship::GetLives()'
undefined reference to `Ship::SetLives(int)'
undefined reference to `Ship::GetLives()'
undefined reference to `Character::IsDead()'
undefined reference to `Character::Character()'
undefined reference to `Character::Character()'
undefined reference to `Ship::Ship()'
undefined reference to `Laser::Laser()'
undefined reference to `Laser::Laser()'
collect2: ld returned 1 exit status
Execution terminated


It seems like I have a problem with my made libraries. If that is what you guys think too, then I could post the libraries as well...

Thank You!
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3548
  • View blog
  • Posts: 10,986
  • Joined: 05-May 12

Re: Delete Function error

Posted 11 January 2013 - 07:41 PM

Just show us your makefile. Are you sure your link line includes your library?
Was This Post Helpful? 0
  • +
  • -

#13 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 11 January 2013 - 08:21 PM

Ship.h

#ifndef SHIP_H
#define SHIP_H
#include "Character.h"

class Ship: public Character{

public:
       Ship();
       
       int GetLives();
       void SetLives( int newValue);
       

private:
        int lives;

};

#endif



Character.h
#ifndef CHARACTER_H
#define CHARACTER_H
#define MAX_X 620
#define MIN_X 0
#define MAX_Y 460
#define MIN_Y 0
#include <allegro.h>

class Character{

public:
       Character();

       int GetX();
       void SetX( int newValue, BITMAP* tempBitmap, BITMAP* spriteToDraw);
       
       int GetY();
       void SetY( int newValue, BITMAP* tempBitmap, BITMAP* spriteToDraw);
       
       void EraseOldSprite( BITMAP* tempBitmap);
       void DrawNewSprite( BITMAP* tempBitmap, BITMAP* spriteToDraw);
       
       bool IsDead();
       void SetDead( bool newValue, BITMAP* tempBitmap);

protected:
        int x;
        int y;
        
        bool visible;
        bool dead;

};

#endif



Laser.h
#ifndef LASER_H
#define LASER_H 1
#include "Character.h"
#include "Ship.h"

class Laser: public Character{

public:
       Laser();
       void CheckCollision(Character objectsToCheck[], BITMAP* tempBitmap);
       bool CheckCollision(Character player, BITMAP* tempBitmap);
       

};

#endif


Was This Post Helpful? 0
  • +
  • -

#14 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3548
  • View blog
  • Posts: 10,986
  • Joined: 05-May 12

Re: Delete Function error

Posted 11 January 2013 - 08:28 PM

Those are your header files. Can you show us your makefile?
Was This Post Helpful? 0
  • +
  • -

#15 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 11 January 2013 - 09:10 PM

what is a make file?
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3