Thread: Pointer&Array problem

  1. #1
    C++ n00bie :D
    Join Date
    Jul 2004

    Pointer&Array problem

    Im making a little graphics engine, but not much about that in this topic. My problem right now is with pointers and arrays(if you didnt notice)

    I have a Dynamic 3D array, which 'seems' to work, havent gotten an error from it, but I was wondering, because its an array of structs, which is in an array of class's, how would I access it?

    'class[0]->struct[0]->variable'? That was my first guess, but it seems to run errors...

    Also, how would I declare an instance of my class, and would I need to declare my struct?

    Thanks for any help, its my first time working with an array of structs/class's

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Show how you declare and initialise these structures / arrays
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Manassas, VA USA

    Thumbs up

    this topic looks kinda good.. i look forward to seeing some code
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Registered User
    Join Date
    Mar 2002
    My interpretation of a 3D array of structs which is in an array of classes
    struct Enigma
    	int color;
    	int shade;
    class holdingClass
    	 Enigma enigmaArray[10][10][10];
    holdingClass game[10];
    if game and enigmaArray are declared with static memory as above then to access a given Enigma member in game you would do this:


    if enigma is declared using dynamic memory, but game uses static memory, then:


    if both enigma and game are declared using dynamic memory then:


    It gets a little more complicated if game or enigmaArray are declared with private access, but it's still doable.

  5. #5
    C++ n00bie :D
    Join Date
    Jul 2004
    Ok heres some code:
    //In class:
    struct tile ***iso_map;
    //Declaring 3D array of structs:
    **iso_map=new int[map_height]; //dynamically declare 3D array
    for (int a=0; a<map_height; a++) {
        *iso_map[a]=new int[map_width];
        for (int b; b<map_width; b++) {
            iso_map[a][b]=new int[map_length];
    //Above class:
    class map *maps;
    //Declaring map(only 1 right now):
    maps=new class[1];
    Thats what is there right now, split alot of course cause its like 250 lines of code

    After looking at your stuff, there seems to be a better way to declare the array of class's, but the problem is that Im using a header file to declare the maps and such, and they arent at the top of the file(need to be below class and struct) Im starting to think that I should change it to file i/o now instead of later? I think that might fix. Ill go through my code, fix it up, and try posting more later.
    Until then, you guys try to help

    Edit: Heres the last error'd line, annoying one it is. Gives me a few things to ask, but first the code:
    draw_sprite(buffer, (BITMAP *)tiles[maps[0].iso_map[z][x][y].tilename].dat, (maps[0].map_start[0])+(x*(maps[0].map_difference[0])), (maps[0].map_start[1])+(y*(maps[0].map_difference[1]));
    (Long, eh? )
    1. Can you declare what tile in the method I used, or is there a problem in that?
    2. Why does it act like 'tiles' is a function?
    3. Where is the syntax error?(Im guessing the tiles thing)
    Last edited by LloydUzari; 08-15-2004 at 02:32 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM