array of pointer objects

This is a discussion on array of pointer objects within the C++ Programming forums, part of the General Programming Boards category; Okay.. I have and object named Enemy_1. I need 5 of these objects. So I created five: Code: Enemy_1 *Enemy[1] ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    180

    array of pointer objects

    Okay..
    I have and object named Enemy_1. I need 5 of these objects. So I created five:

    Code:
            Enemy_1 *Enemy[1] = new Enemy_1;
            Enemy_1 *Enemy[2]= new Enemy_1;
            Enemy_1 *Enemy[3]= new Enemy_1;
            Enemy_1 *Enemy[4]= new Enemy_1;
            Enemy_1 *Enemy[5]= new Enemy_1;
    and then externed them

    Code:
    extern        Enemy_1 *Enemy[1];
    extern        Enemy_1 *Enemy[2];
    extern        Enemy_1 *Enemy[3];
    extern        Enemy_1 *Enemy[4];
    extern        Enemy_1 *Enemy[5];
    Then assign various values to them using a for loop like so:
    Code:
     for(i=1;i<6;i++)
    {
                               Enemy[i]->Enemy1_Sprite->Picture->LoadFromFile("ship-5.bmp");
    }
    And boy does the compiler not like em!(Borland c++ Builder 6, win xp)

    these are the errors i get:

    With the extern part:
    Code:
    [C++ Error] Global_Var.h(6): E2356 Type mismatch in redeclaration of 'Enemy'
      [C++ Error] Global_Var.h(5): E2344 Earlier declaration of 'Enemy'
      [C++ Error] Global_Var.h(7): E2356 Type mismatch in redeclaration of 'Enemy'
      [C++ Error] Global_Var.h(5): E2344 Earlier declaration of 'Enemy'
      [C++ Error] Global_Var.h(8): E2356 Type mismatch in redeclaration of 'Enemy'
      [C++ Error] Global_Var.h(5): E2344 Earlier declaration of 'Enemy'
      [C++ Error] Global_Var.h(9): E2356 Type mismatch in redeclaration of 'Enemy'
      [C++ Error] Global_Var.h(5): E2344 Earlier declaration of 'Enemy'
    With the declare part

    Code:
    [C++ Error] Lvl1.h(15): E2034 Cannot convert 'Enemy_1 *' to 'Enemy_1 *[1]'
      [C++ Error] Lvl1.h(16): E2238 Multiple declaration for 'Enemy'
      [C++ Error] Lvl1.h(15): E2344 Earlier declaration of 'Enemy'
      [C++ Error] Lvl1.h(16): E2034 Cannot convert 'Enemy_1 *' to 'Enemy_1 *[2]'
      [C++ Error] Lvl1.h(17): E2238 Multiple declaration for 'Enemy'
      [C++ Error] Lvl1.h(16): E2344 Earlier declaration of 'Enemy'
      [C++ Error] Lvl1.h(17): E2034 Cannot convert 'Enemy_1 *' to 'Enemy_1 *[3]'
      [C++ Error] Lvl1.h(18): E2238 Multiple declaration for 'Enemy'
      [C++ Error] Lvl1.h(17): E2344 Earlier declaration of 'Enemy'
      [C++ Error] Lvl1.h(18): E2034 Cannot convert 'Enemy_1 *' to 'Enemy_1 *[4]'
      [C++ Error] Lvl1.h(19): E2238 Multiple declaration for 'Enemy'
      [C++ Error] Lvl1.h(18): E2344 Earlier declaration of 'Enemy'
      [C++ Error] Lvl1.h(19): E2034 Cannot convert 'Enemy_1 *' to 'Enemy_1 *[5]'
    and where I try to use them:

    Code:
      [C++ Warning] Lvl1.h(35): W8004 'Enemy' is assigned a value that is never used
      [C++ Warning] Lvl1.h(35): W8004 'Enemy' is assigned a value that is never used
      [C++ Warning] Lvl1.h(35): W8004 'Enemy' is assigned a value that is never used
      [C++ Warning] Lvl1.h(35): W8004 'Enemy' is assigned a value that is never used

    THanks for the help


    Cheers

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    you have 5 array's named Enemy. Even if you did have different names for each of them, you are setting arrays of 2, 3, 4, and 5 Enemy_1 pointers all being set to one new enemy. That's just silly.
    Last edited by skorman00; 04-09-2004 at 07:32 PM.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    *Smacks Head*

    OMFG! I can't beleive I did that!


    wow...wow..

    thx



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  2. Returning an Array of Pointers to Objects
    By randomalias in forum C++ Programming
    Replies: 4
    Last Post: 04-29-2006, 03:45 PM
  3. Pros pls help, Pointer to array
    By kokopo2 in forum C Programming
    Replies: 7
    Last Post: 08-17-2005, 12:07 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21