Sign in to follow this  
raptorstrike

function problem *solved*

Recommended Posts

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[i][j];
        for( j=3; j>0; j--)
        {
            identifire = array2[i][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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ) 

Share this post


Link to post
Share on other sites
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:

Share this post


Link to post
Share on other sites
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); // works
foo(42); // works

void bar(int & x); // The & specifies "pass by reference",
// but DOES NOT CHANGE the expected parameter type.
bar(y); // works
bar(42); // works
bar(&y); // NO! This looks up the address of y, interprets the
// address as an integer, and passes *that* by reference.



BTW, nice project name ;\

Share this post


Link to post
Share on other sites
After reading your post carefully, I think I know what's wrong. When you pass the arrays into the function (i.e. not the declaration or the definition, but the calling), you should not put the subscripts next to the variables. To the compiler this means that you are trying to get the 4th bitmap from the array (which doesn't exist BTW) and the 12th tile in the way (which also doesn't exist).

So when calling the function, you should have:

the_tile.draw_tile(x,y,identifire,array,array2)



What is the purpose of passing in the variable identifire (it's spelled identifier BTW)? You have to realize that that variable will not be changed once the function returns (the identifire in the function is a local variable). Also, the comparisons in your if statements use the assigment operator (=) instead of the equivalency operator (==). This will cause the statements to be called unexpectedly.

if (identifire=0)
/* ... */
if (identifire=1)
/* ... */
if (identifire=2)
/* ... */

should be:

if (identifire == 0)
/* ... */
if (identifire == 1)
/* ... */
if (identifire == 2)
/* ... */

Share this post


Link to post
Share on other sites
You also don't forward declare member functions like you do. If you want class tile to have member draw, you declare it as:


class tile {
public:
void draw( arguments go here );
};


PS: I edited your initial code to be better formatted.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this