function problem *solved*

Started by
10 comments, last by hplus0603 19 years, 7 months ago
ok im declaring a funciton

void tile::draw_tile(int x,int y,int identifire,BITMAP * array[3],int array2[2][3]);
and defining it here

void tile::draw_tile(int x, int y, int identifire, BITMAP * array[3], int array2[2][3])
{
    int i; 
    int j;
    for( i=2; i>0; i--)
    {
        identifire = array2[j];
        for( j=3; j>0; j--)
        {
            identifire = array2[j];
            int k = identifire;
            if (identifire=0)
            {      
             masked_blit(array[k],screen,0,0,x,y,41,41);
            };
            if (identifire=1)
            {
             masked_blit(array[k],screen,0,0,x,y,41,41);
            };
            if (identifire=2)
            {    
             masked_blit(array[k],screen,0,0,x,y,41,41);
             /*whats going on here
             ok basicly were passing an array of tiles into the function
             then we read there tiles via the if statements
             then the current array number is stored in identifire
             then the data is read by the if statements and the tiles renderd accordingly
             */
            }; 
        };
    };                  
};   
but when i use it here

the_tile.draw_tile(x,y,identifire,array[3],array2[2][3])
it gives me errors saying 55 C:\Dev-Cpp\main\main.cpp no matching function for call to `tile::draw_tile( int, int, int, BITMAP*&, int&)' error C:\Dev-Cpp\main\tile.h:8 candidates are: void tile::draw_tile(int, int, int, BITMAP**, int (*)[3]) i understand what it means it mean it wants me to use pure numbers instead of variables what i dont know is how to fix it thanks for your help [Edited by - hplus0603 on September 1, 2004 8:13:08 PM]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
First of all, you should get rid of the array subscripts in the function declaration and definition. The compiler only needs to know the type of the elements in the arrays, not their dimensions
void tile::draw_tile(int x, int y, int identifire, BITMAP *array, int array2);


There may be more to it than that, but this will be a step in the right direction.
You are not the one beautiful and unique snowflake who, unlike the rest of us, doesn't have to go through the tedious and difficult process of science in order to establish the truth. You're as foolable as anyone else. And since you have taken no precautions to avoid fooling yourself, the self-evident fact that countless millions of humans before you have also fooled themselves leads me to the parsimonious belief that you have too.--Daniel Rutter
ok but now i get lots of

tile.cpp:5: error: invalid types `int[int]' for array subscript
tile.cpp:10: error: invalid types `int[int]' for array subscript
tile.cpp:13: error: invalid types `int[int]' for array subscript
tile.cpp:17: error: cannot convert `BITMAP' to `BITMAP*' for argument `1' to `
void masked_blit(BITMAP*, BITMAP*, int, int, int, int, int, int)'
tile.cpp:21: error: cannot convert `BITMAP' to `BITMAP*' for argument `1' to `
void masked_blit(BITMAP*, BITMAP*, int, int, int, int, int, int)'
tile.cpp:25: error: cannot convert `BITMAP' to `BITMAP*' for argument `1' to `
void masked_blit(BITMAP*, BITMAP*, int, int, int, int, int, int)'basicly it cause alot more errors and unless its vital for my code i dont feel like messing with it right now maybe during the optimization prosses later (like when im near compleation)
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
besides dosent the function see the array as a non-subscrip data form if you declare it like that?( aregular variable)
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Sorry, my mistake. The arrays should be listed as pointers to the element type. Like this:
void tile::draw_tile(int x, int y, int identifire, BITMAP **array, int *array2);
You are not the one beautiful and unique snowflake who, unlike the rest of us, doesn't have to go through the tedious and difficult process of science in order to establish the truth. You're as foolable as anyone else. And since you have taken no precautions to avoid fooling yourself, the self-evident fact that countless millions of humans before you have also fooled themselves leads me to the parsimonious belief that you have too.--Daniel Rutter
Although I'm not sure if this is the entire problem, what Plasmadog wrote should actually be:

void tile::draw_tile(int x, int y, int identifire, BITMAP **, int **)

as the function definition and declaration.

Edit: It looks to me from your original error messages that you are trying to call draw_tile while passing it references instead of pointers.
You lack some understanding about how to use arrays as parameters. I never do it so I'm not exactly clear on the syntax, but I can point out your mistakes.

Your fourth parameter ("BITMAP * array[3]") is an array of pointers. Your fifth parameter ("int array2[2][3]") is an array of ints. When you call the function, you have to pass those types of parameters. In your function call, the fourth parameter is a pointer, not an array of pointers, and the fifth parameter is an int, not an array of ints. Perhaps you are confused about the syntax. It appears that you might think that you have to include declaration info in the function call, but you don't. Perhaps you want to call the function like this instead:
    the_tile.draw_tile( x, y, identifire, array, array2 ) 
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
ok i know what the problem is the problem is that

in one function im passing

draw_tile(int x, int y, int identifire, BITMAP * array[3], int array2[2][3])//right here all of my paramaters are pure just prototype int and the function doesnt see them as variables it sees them as "(int, int, int, BITMAP**, int (*)[3]) were as here it sees them as 8 C:\Dev-Cpp\advanced wars\tile.h void tile::draw_tile(int, int, int, BITMAP*, int)
and when i use them externaly i pass them varibles not straght ints
(int&, int&, int&, BITMAP*&, int&)'
so what i need to do is pass int& ect. into my prototype but i dont know how to do that (cant get there from here)

here is my source code

#include "main.h"#include "allegro.h"#include "tile.h"int main(int argc, char *argv[]){    tile the_tile;    DATAFILE *datafile;     BITMAP * array[3];     int identifire;     int array2[2][3];     int x;     int y;     array2[2][3]= 1,2,0,2,1,0;    (BITMAP *) datafile[mountain].dat;    (BITMAP *) datafile[plains].dat;    array[3]=(BITMAP *)datafile[river_ver].dat,datafile[mountain].dat,datafile[plains].dat;       char buf[256];   allegro_init();   install_keyboard();    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED , 320, 200, 0, 0) != 0) {      set_gfx_mode(GFX_TEXT , 0, 0, 0, 0);      allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);      return 1;   set_color_depth(32);   }   /* load the datafile into memory */   replace_filename(buf, argv[0], "datafile.dat", sizeof(buf));   datafile = load_datafile(buf);   if (!datafile) {      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);      allegro_message("Error loading %s!\n", buf);      return 1;   }     int templat[2][3]={1,0,1,2,2,0};   set_palette((RGB *)datafile[main_palette].dat);   /* aha, set a palette and let Allegro convert colors when blitting */   set_color_conversion(COLORCONV_TOTAL);      /* display the bitmap from the datafile */   textout(screen, font, "This is the bitmap:", 32, 16, makecol(255, 0, 255));   the_tile.draw_tile(x,y,identifire,array[3],array2[2][3]);         /* and use the font from the datafile */  // textout(screen, datafile[BIG_FONT].dat, "And this is a big font!", 32, 128,//	   makecol(0, 255, 0));   readkey();   /* unload the datafile when we are finished with it */   unload_datafile(datafile);   return 0;}END_OF_MAIN();//As you can see array[3] is in fact an array of pointers:
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
well i dont know what the problem was the [][] on my arrays i got rid of those a vola well thanks every one
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
When you *call* the function that expects an *array*, *pass an array*. Do *not* write subscripts when you refer to the array when you're *calling* it, because that *does not* specify the size of the array, but instead subscripts the array and retrieves an element. You don't want to pass an element, you want to pass the array.

You don't need to, and indeed shouldn't try to, do anything special in order to work with references.
void foo(int x);int y = 42;foo(y); // worksfoo(42); // worksvoid bar(int & x); // The & specifies "pass by reference",// but DOES NOT CHANGE the expected parameter type.bar(y); // worksbar(42); // worksbar(&y); // NO! This looks up the address of y, interprets the // address as an integer, and passes *that* by reference.


BTW, nice project name ;\

This topic is closed to new replies.

Advertisement