If you put a array in the intialiaztion of a function, do you have to put an array when you call it? Because I am getting an error that says something lacks a cast. Is there any way around this?
This is a discussion on A simple array question within the C++ Programming forums, part of the General Programming Boards category; If you put a array in the intialiaztion of a function, do you have to put an array when you ...
If you put a array in the intialiaztion of a function, do you have to put an array when you call it? Because I am getting an error that says something lacks a cast. Is there any way around this?
dont really understand the question.... if you would post the func. declaration,implementation and a small example of you calling it i could be more help.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
I know, I am going to shrink the function later. The function compiles ok, it's supposed to, nothing is wrong with the function. But when I call it using a variable, with an array or not, it says the variable lacks a cast.Code:int NumberLine(int number[4],int xpos,int ypos) { int digit1=number[0]; int digit2=number[1]; int digit3=number[2]; int digit4=number[3]; int digit5=number[4]; BITMAP one; BITMAP two; BITMAP three; BITMAP four; BITMAP five; BITMAP six; BITMAP seven; BITMAP eight; BITMAP nine; BITMAP space; BITMAP zero; load_bmp("0.bmp",&zero); load_bmp("1.bmp",&one); load_bmp("2.bmp",&two); load_bmp("3.bmp",&three); load_bmp("4.bmp",&four); load_bmp("5.bmp",&five); load_bmp("6.bmp",&six); load_bmp("7.bmp",&seven); load_bmp("8.bmp",&eight); load_bmp("9.bmp",&nine); load_bmp("space.bmp",&space); switch (digit1) { case '0': draw_transparent_bitmap(&zero,xpos,ypos); xpos=xpos+12; break; case '1': draw_transparent_bitmap(&one,xpos,ypos); xpos=xpos+12; break; case '2': draw_transparent_bitmap(&two,xpos,ypos); xpos=xpos+12; break; case '3': draw_transparent_bitmap(&three,xpos,ypos); xpos=xpos+12; break; case '4': draw_transparent_bitmap(&four,xpos,ypos); xpos=xpos+12; break; case '5': draw_transparent_bitmap(&five,xpos,ypos); xpos=xpos+12; break; case '6': draw_transparent_bitmap(&six,xpos,ypos); xpos=xpos+12; break; case '7': draw_transparent_bitmap(&seven,xpos,ypos); xpos=xpos+12; break; case '8': draw_transparent_bitmap(&eight,xpos,ypos); xpos=xpos+12; break; case '9': draw_transparent_bitmap(&nine,xpos,ypos); xpos=xpos+12; break; } switch (digit2) { case '0': draw_transparent_bitmap(&zero,xpos,ypos); xpos=xpos+12; break; case '1': draw_transparent_bitmap(&one,xpos,ypos); xpos=xpos+12; break; case '2': draw_transparent_bitmap(&two,xpos,ypos); xpos=xpos+12; break; case '3': draw_transparent_bitmap(&three,xpos,ypos); xpos=xpos+12; break; case '4': draw_transparent_bitmap(&four,xpos,ypos); xpos=xpos+12; break; case '5': draw_transparent_bitmap(&five,xpos,ypos); xpos=xpos+12; break; case '6': draw_transparent_bitmap(&six,xpos,ypos); xpos=xpos+12; break; case '7': draw_transparent_bitmap(&seven,xpos,ypos); xpos=xpos+12; break; case '8': draw_transparent_bitmap(&eight,xpos,ypos); xpos=xpos+12; break; case '9': draw_transparent_bitmap(&nine,xpos,ypos); xpos=xpos+12; break; } switch (digit3) { case '0': draw_transparent_bitmap(&zero,xpos,ypos); xpos=xpos+12; break; case '1': draw_transparent_bitmap(&one,xpos,ypos); xpos=xpos+12; break; case '2': draw_transparent_bitmap(&two,xpos,ypos); xpos=xpos+12; break; case '3': draw_transparent_bitmap(&three,xpos,ypos); xpos=xpos+12; break; case '4': draw_transparent_bitmap(&four,xpos,ypos); xpos=xpos+12; break; case '5': draw_transparent_bitmap(&five,xpos,ypos); xpos=xpos+12; break; case '6': draw_transparent_bitmap(&six,xpos,ypos); xpos=xpos+12; break; case '7': draw_transparent_bitmap(&seven,xpos,ypos); xpos=xpos+12; break; case '8': draw_transparent_bitmap(&eight,xpos,ypos); xpos=xpos+12; break; case '9': draw_transparent_bitmap(&nine,xpos,ypos); xpos=xpos+12; break; } switch (digit4) { case '0': draw_transparent_bitmap(&zero,xpos,ypos); xpos=xpos+12; break; case '1': draw_transparent_bitmap(&one,xpos,ypos); xpos=xpos+12; break; case '2': draw_transparent_bitmap(&two,xpos,ypos); xpos=xpos+12; break; case '3': draw_transparent_bitmap(&three,xpos,ypos); xpos=xpos+12; break; case '4': draw_transparent_bitmap(&four,xpos,ypos); xpos=xpos+12; break; case '5': draw_transparent_bitmap(&five,xpos,ypos); xpos=xpos+12; break; case '6': draw_transparent_bitmap(&six,xpos,ypos); xpos=xpos+12; break; case '7': draw_transparent_bitmap(&seven,xpos,ypos); xpos=xpos+12; break; case '8': draw_transparent_bitmap(&eight,xpos,ypos); xpos=xpos+12; break; case '9': draw_transparent_bitmap(&nine,xpos,ypos); xpos=xpos+12; break; } switch (digit5) { case '0': draw_transparent_bitmap(&zero,xpos,ypos); xpos=xpos+12; break; case '1': draw_transparent_bitmap(&one,xpos,ypos); xpos=xpos+12; break; case '2': draw_transparent_bitmap(&two,xpos,ypos); xpos=xpos+12; break; case '3': draw_transparent_bitmap(&three,xpos,ypos); xpos=xpos+12; break; case '4': draw_transparent_bitmap(&four,xpos,ypos); xpos=xpos+12; break; case '5': draw_transparent_bitmap(&five,xpos,ypos); xpos=xpos+12; break; case '6': draw_transparent_bitmap(&six,xpos,ypos); xpos=xpos+12; break; case '7': draw_transparent_bitmap(&seven,xpos,ypos); xpos=xpos+12; break; case '8': draw_transparent_bitmap(&eight,xpos,ypos); xpos=xpos+12; break; case '9': draw_transparent_bitmap(&nine,xpos,ypos); xpos=xpos+12; break; } } NumberLine(maincharacter.bHP,50,50);
didnt look any further than this...
int digit5=number[4];
there is no number[4]....
look at the dec....
int NumberLine(int number[4],int xpos,int ypos)
a function that returns an int and takes an array of ints of only this size[4] and two other ints.
so as array size is [4] top array element is [3]
fix that first. then post again and include def of mainchar struct.
Last edited by Stoned_Coder; 11-25-2001 at 09:18 AM.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
1) you have specified that you can only call this function with an array[4]
you cant call it with an array[3] or an array[5]. Get the picture.
2) You are accessing past the bounds of your array..... see previous post.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
look, dude I am not having any problems with the ints, ok. It is only when I call the function. If I put "1234" where I put maincharacter.bATK, it works just fine. But if I throw a variable in there, it doesn't want to work. I tried a array in the place of it, and it gave me a different error, saying invalid types.