Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Illegal Function Call

This thread is locked; no one can reply to it. rss feed Print
Illegal Function Call
agonvs
Member #15,917
March 2015

Argh! What am I doing wrong here?

Here's the error I get: It occurs on line 47:

1>..\..\shell\shell\skeleton.cpp(47): error C2660: 'Player::Initialize' : function does not take 4 arguments

Here's skeleton.cpp:

#SelectExpand
1 #include<allegro5/allegro.h> 2 #include<allegro5/allegro_primitives.h> 3 #include<allegro5/allegro_image.h> 4 #include<allegro5/allegro_audio.h> 5 #include<allegro5/allegro_acodec.h> 6 #include<iostream> 7 #include<fstream> 8#include"entityclass.h" 9#include"c:\playerclass.h" 10#include"globals.h" 11 using namespace std; 12 13 int main() 14 { 15 float gameTime = 0; 16 int frames = 0; 17 int gameFPS = 0; 18 if(!(al_init())) 19 cout << "Couldn't initialize Allegro." << cout; 20 if(!(al_install_joystick())) 21 cout << "Couldn't install joystick." << endl; 22 al_init_image_addon(); 23 al_init_primitives_addon(); 24 ALLEGRO_DISPLAY *display = NULL; 25 display = al_create_display(1280,720); 26 ALLEGRO_BITMAP* bkgd; 27 bkgd = al_load_bitmap("bkgd.pcx"); 28 29 ALLEGRO_EVENT_QUEUE *event_queue = NULL; 30 event_queue = al_create_event_queue(); 31 if(!event_queue) 32 cout << "al_create_event_queue failed." << endl; 33 ALLEGRO_TIMER *timer; 34 timer = al_create_timer(1.0/60); 35 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 36 gameTime = al_current_time(); 37 al_register_event_source(event_queue, al_get_joystick_event_source()); 38 ALLEGRO_JOYSTICK* joy = al_get_joystick(0); 39 ALLEGRO_JOYSTICK_STATE jst; 40 //~ buttons button; 41 direction dir = RIGHT; 42 bool alive = true; 43 bool render=false; 44 al_start_timer(timer); 45 int x = 0, y = -720; 46 Player player; 47 player.Initialize(513, 319, 0, 0); 48 while(alive) 49 { 50 ALLEGRO_EVENT ev; 51 al_wait_for_event(event_queue, &ev); 52 al_get_joystick_state(joy, &jst); 53 if (ev.type == ALLEGRO_EVENT_JOYSTICK_AXIS) 54 { 55 if (((jst.stick[2].axis[0] == 0) && (jst.stick[2].axis[1] == 0)) || ((jst.stick[1].axis[0] == 0) && (jst.stick[1].axis[1] == 0)) || ((jst.stick[3].axis[0] == 0) && (jst.stick[0].axis[1] == 0))) 56 dir = NONE; 57 if (((jst.stick[2].axis[0] == 1) && (jst.stick[2].axis[1] == 0)) || ((jst.stick[1].axis[0] == 1) && (jst.stick[1].axis[1] == 0)) || ((jst.stick[3].axis[0] == 1) && (jst.stick[0].axis[1] == 0))) 58 dir = RIGHT; 59 if (((jst.stick[2].axis[0] == -1) && (jst.stick[2].axis[1] == 0)) || ((jst.stick[1].axis[0] == -1) && (jst.stick[1].axis[1] == 0)) || ((jst.stick[3].axis[0] == -1) && (jst.stick[0].axis[1] == 0))) 60 dir = LEFT; 61 } 62 //~ if (ev.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN) 63 //~ if (jst.button[9]) 64 //~ button = NINE; 65 //update 66 else if (ev.type == ALLEGRO_EVENT_TIMER) 67 { 68 render = true; 69 player.Update(); 70 if (dir == LEFT) 71 { 72 73 } 74 if (dir == RIGHT) 75 { 76 77 } 78 79 if (al_current_time() - gameTime >= 1) 80 { 81 gameTime = al_current_time(); 82 gameFPS = frames; 83 frames = 0; 84 } 85 } 86 87 //render 88 if (render && al_is_event_queue_empty(event_queue)) 89 { 90 //~ al_set_target_bitmap(al_get_backbuffer(display)); 91 92 al_clear_to_color(al_map_rgb_f(0,0,0)); 93 al_draw_bitmap(bkgd, x, y, 0); 94 player.Render(); 95 al_flip_display(); 96 97 98 } 99 100 if (jst.button[9]) 101 alive = false; 102 } 103 //~ al_destroy_bitmap(image); 104 al_destroy_timer(timer); 105 al_destroy_event_queue(event_queue); 106 return 0; 107 }

Here's playerclass.cpp:

#SelectExpand
1#include "entityclass.h" 2#include"playerclass.h" 3#include<allegro5\allegro5.h> 4 5void Player::Initialize(int x, int y, int velX, int velY) 6{ 7 mX = x; 8 mY = y; 9 mVelX = velX; 10 mVelY = velY; 11 idleAnim[0] = 1; 12 idleAnim[1] = 2; 13 idleAnim[2] = 3; 14 idleAnim[3] = 2; 15 idle = true; 16 dying = false; 17 injured = false; 18 jumping = false; 19 falling = false; 20 shooting = false; 21 idleForward = true; 22 tint = false; 23 flipped = false; 24 r = 1; 25 g = 0; 26 b = 0; 27 transparency = 0; 28 lowerFrame = 0; 29 upperFrame = 1; 30 count = 0; 31 index = 0; 32 image = al_load_bitmap("idle.png"); 33} 34 35void Player::Update() 36{ 37 if (idle) 38 { 39 if (count == 5) 40 { 41 if (index == 3) 42 { 43 index = 0; 44 } 45 index++; 46 lowerFrame = 0; 47 upperFrame = idleAnim[index]; 48 count = 0; 49 } 50 count++; 51 } 52} 53 54void Player::Render() 55{ 56 if (tint) 57 if (flipped) 58 { 59 al_draw_tinted_bitmap(image, al_map_rgba_f(r, g, b, transparency), mX, mY, ALLEGRO_FLIP_HORIZONTAL); 60 al_draw_tinted_bitmap(image, al_map_rgba_f(r, g, b, transparency), mX, mY, ALLEGRO_FLIP_HORIZONTAL); 61 } 62 else 63 { 64 al_draw_tinted_bitmap(image, al_map_rgba_f(r, g, b, transparency), mX, mY, 0); 65 al_draw_tinted_bitmap(image, al_map_rgba_f(r, g, b, transparency), mX, mY, 0); 66 } 67 else 68 if (flipped) 69 { 70 al_draw_bitmap(image, mX, mY, ALLEGRO_FLIP_HORIZONTAL); 71 al_draw_bitmap(image, mX, mY, ALLEGRO_FLIP_HORIZONTAL); 72 } 73 else 74 { 75 al_draw_bitmap_region(image, (lowerFrame * 256), 0, 256, 256, mX, mY, 0); 76 al_draw_bitmap_region(image, (upperFrame * 256), 0, 256, 256, mX, mY, 0); 77 } 78}

And, finally, playerclass.h:

#SelectExpand
1#pragma once 2#include "entityclass.h" 3#include<allegro5\allegro.h> 4 5class Player: public Entity 6{ 7private: 8 bool idle, dying, injured, jumping, falling, shooting, idleForward, tint, flipped; 9 float r, g, b, transparency; 10 int lowerFrame, upperFrame, count, mX, mY, mVelX, mVelY, mWidth, mHeight, index; 11 int idleAnim[4]; 12 ALLEGRO_BITMAP* image; 13 14public: 15 void Initialize(int x, int y, int velX, int velY); 16 void Update(); 17 void Render(); 18 bool collide(int collideX, int collideY, int width, int height); 19 int getVelX(){return mVelX;} 20 int getVelY(){return mVelY;} 21};

Please help! This is driving me crazy! ???

Johan Halmén
Member #1,550
September 2001

Check for multiple files of playerclass.h or playerclass.cpp. Your project file might point to the wrong file, if you have two of them. Or you might have edited one file and not saved it and for this post you copied and pasted the code from the unsaved file, while your compiler reads the saved file. Or you might have edited and saved the .h file, but your IDE doesn't rebuild that part automatically. Rebuild everything.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

In one instance you are including the playerclass.h from c:\ and in the other from another folder, whereever you are compiling from and have set the include path to.

#include"c:\playerclass.h" 

#include"playerclass.h" 

Unless you're compiling from the c:\ drive root folder, then you are including different files. This could be causing your problems. If you're referring to an old version of playerclass.h. And you would probably get a link error too, about undefined references, if you got that far.

Go to: