Array Subscript Error



  • Mit Vergnügen

    struct material {
    	uint8 size_of;
    	uint8 priority;
    	bool lightened;
    	struct size16 {
    		 uint8 alphamap[16][16];
    		 uint8 depthmap[16][16];
    		uint16 colormap[16][16];
    		 uint8 shinemap[16][16];	};
    	struct size32 {
    		 uint8 alphamap[32][32];
    		 uint8 depthmap[32][32];
    		uint16 colormap[32][32];
    		 uint8 shinemap[32][32];	};
    	struct size64 {
    		 uint8 alphamap[64][64];
    		 uint8 depthmap[64][64];
    		uint16 colormap[64][64];
    		 uint8 shinemap[64][64];	};
    	};
    

    Der Struct

    void encode_material(/*sources*/material source , uint8 material_size , uint8 priority , bool light_culled , uint8 alpha_source[] , uint8 depth_source[] , uint16 color_source[] , uint8 shine_source[] ) {
    			source.lightened = light_culled;
    			source.priority  = priority;
    			source.size_of	 = material_size;
    			switch (material_size) {
    				case 16:
    					for (uint8 i = 1; i <= material_size ; i++){
    					for (uint8 j = 1; j <= material_size ; j++){
    					source.size16.alphamap[i][j] = alpha_source[i][j];
    					source.size16.depthmap[i][j] = depth_source[i][j];
    					source.size16.colormap[i][j] = color_source[i][j];
    					source.size16.shinemap[i][j] = shine_source[i][j];
    					}
    					}
    					break;
    				case 32:
    					for (uint8 i = 1; i <= material_size ; i++){
    					for (uint8 j = 1; j <= material_size ; j++){
    					source.size32.alphamap[i][j] = alpha_source[i][j];
    					source.size32.depthmap[i][j] = depth_source[i][j];
    					source.size32.colormap[i][j] = color_source[i][j];
    					source.size32.shinemap[i][j] = shine_source[i][j];
    					}
    					}
    					break;
    				case 64:
    					for (uint8 i = 1; i <= material_size ; i++){
    					for (uint8 j = 1; j <= material_size ; j++){
    					source.size64.alphamap[i][j] = alpha_source[i][j];
    					source.size64.depthmap[i][j] = depth_source[i][j];
    					source.size64.colormap[i][j] = color_source[i][j];
    					source.size64.shinemap[i][j] = shine_source[i][j];
    					}
    					}
    					break;
    				}
    			}
    

    Die Funktion (Recht langer Funktionskopf 😉 )



  • Tja, Du hast innerhalb der struct drei Typen deklariert namens material::size16, material::size32 und material::size64 (nested classes), nicht etwa Objekte davon.

    struct material {
      struct size16 {
        /* ... */
      };
      size16 size16_elem;
    };
    


  • Aaaaaaaaaachso , mist , hätt mir klar sein müssen 👍 Thx



  • Naja , das is zwar schon richtig , aber :

    base.h:55: error: invalid types 'unsigned char[int]' for array subscript
    base.h:56: error: invalid types 'unsigned char[int]' for array subscript
    base.h:57: error: invalid types 'short unsigned int[int]' for array subscript
    base.h:58: error: invalid types 'unsigned char[int]' for array subscript
    base.h:65: error: invalid types 'unsigned char[int]' for array subscript
    base.h:66: error: invalid types 'unsigned char[int]' for array subscript
    base.h:67: error: invalid types 'short unsigned int[int]' for array subscript
    base.h:68: error: invalid types 'unsigned char[int]' for array subscript
    base.h:75: error: invalid types 'unsigned char[int]' for array subscript
    base.h:76: error: invalid types 'unsigned char[int]' for array subscript
    base.h:77: error: invalid types 'short unsigned int[int]' for array subscript
    base.h:78: error: invalid types 'unsigned char[int]' for array subscript



  • die Parameter 'alpha_source' etc sind ja auch nur eindimensionale Arrays 😉

    (btw ist es Verschwendung, dort drei structs zu definieren, wenn sowieso nur eins davon gleichzeitig genutzt wird)



  • Wenn ich im Funktionskopf zwei Array Klammern , also [][] mache , dann bekomme ich andere Fehler :

    Mister Compiler schrieb:

    base.h:47: error: declaration of 'alpha_source' as multidimensional array must have bounds for all dimensions except the first
    base.h:47: error: declaration of 'depth_source' as multidimensional array must have bounds for all dimensions except the first
    base.h:47: error: declaration of 'color_source' as multidimensional array must have bounds for all dimensions except the first
    base.h:47: error: declaration of 'shine_source' as multidimensional array must have bounds for all dimensions except the first
    base.h: In function 'void encode_material(material, int, uint8, bool)':
    base.h:55: error: 'alpha_source' was not declared in this scope
    base.h:56: error: 'depth_source' was not declared in this scope
    base.h:57: error: 'color_source' was not declared in this scope
    base.h:58: error: 'shine_source' was not declared in this scope
    base.h:65: error: 'alpha_source' was not declared in this scope
    base.h:66: error: 'depth_source' was not declared in this scope
    base.h:67: error: 'color_source' was not declared in this scope
    base.h:68: error: 'shine_source' was not declared in this scope
    base.h:75: error: 'alpha_source' was not declared in this scope
    base.h:76: error: 'depth_source' was not declared in this scope
    base.h:77: error: 'color_source' was not declared in this scope
    base.h:78: error: 'shine_source' was not declared in this scope
    make: *** [arm9_main.o] Error 1

    Ich brauche statiche Werte für die Arrays , deswegen habe ich 16 32 und 64 gewählt ; ich habs auch schon mit ner Klasse versucht , aber habs net auf die reihe bekommen ...



  • Und was ist an "mehrdimensionale Arrays müssen Grenzen (Werte) für alle Dimensionen ausser der ersten haben" nicht verständlich? 😉

    Oder haperts am Englischen? ➡ ohne Englisch wirds schwer!



  • Wenn ich wüsste , wie ich diese Grenzen definiere wärs etwas einfacher

    PS: Wusst net , was bounds sind



  • Dann mußt du statt int[][] halt geeignet initialisierte int** übergeben (in den FAQs finden sich gewiss ein paar Beispiele, wie man dynamisch Matrixstrukturen anlegt).

    PS: eventuell kannst du statt der fixierten struct's auch solche dynamisch angelegten Felder verwenden - wenn nicht, würde ich eigentlich mit einem Doppelarray auskommen (und ungenutzte Felder leer lassen).



  • 😃 Hat geklappt , THX


Anmelden zum Antworten