Page 1 of 1

How to call void functions (like shoot)

Posted: Tue Nov 04, 2008 1:23 pm
by jhend60
Hi all
I am wondering how to get this thing working. I have finished implementing a shoot function(void shoot()) but , when I try to use it in my code by just using 'shoot()' I get this error:

main.cpp(248) : error C2365: 'shoot' : redefinition; previous definition was 'data variable'
main.cpp(24) : see declaration of 'shoot'

line 248 is where the opening left bracket of shoot is, line 24 is where I call shoot(). What am I doing wrong? I have examined the demo and see nothing different between mine and theirs, except theirs works.
Thanks.

Posted: Tue Nov 04, 2008 2:02 pm
by rogerborg
The error message tells you that the declaration of 'shoot' at line 24 is a 'data variable'. This code generates the same error:

Code: Select all

int shoot;

void shoot() { }
I think we'll need to see your code to figure out exactly how you've managed to confuse the compiler. ;)

Posted: Fri Nov 14, 2008 12:44 am
by Systemerror
You need to define, then declare and then call your function, example.

Code: Select all

//create instance of shoot
void shoot();

//define the shoot funtion
void shoot()
       {
       //all code to shoot
       }

       //call function
      shoot();

//end
try that, thats where I think you went wrong in creating an instance, defining, and calling.

Posted: Fri Nov 14, 2008 8:07 am
by JP
You don't actually need all that code, for example the 'instance' (bad word use there, instance is normally to do with objects that you've created, better word would be declaration), that's not necessary in your snippet of code as the function is defined before the the call anyway. )