-
functions
hey sorry to bother every1
im fairlynew to c++ and im slightly stuck
i have declared 2 fucntions and they work fine however i am now at the stage where i need to call each fucntion from within the other like this:
void fucntion1(){
function2;
}
void fucntion2(){
function1;
}
of course it is slightly more complicated than that but i get the error undeclared identifier is there anyway to get fucntions like the above to work
thanks for ur time
pants
-
call the function using function1() .... its that simple :D
-
And also make sure you actually spell the function name correctly.
-
void function1(); //must say "hey i HAVE declared this function"
void function2();
void function1() // function declaration
{
// your code
}
void function2()
{
//your code
}
/*
nothin to it
also see:
http://www.cprogramming.com/tutorial/lesson4.html
-
yeah i thougt it would have been that easy but for soem reason it keeps sayin that the seocnd function is an undelcarded identifier
int main(){
fucntion1();
return 0;
}
void fucntion1(){
cout<<"helllo";
}
i tried this to but it says 2 errors
1)'fucntion1' : undeclared identifier
2)'fucntion1' : redefinition; different type modifiers
any ideas???
cheers pants
-
Follow Nor's advice - use a function prototype
#include <iostream>
void fucntion1(); //This is a function prototype.
int main(){
fucntion1();
return 0;
}
void fucntion1(){
cout<<"helllo";
}
-
/*-----Start Cut-------------*/
//Must declare a function before you can use it
#include <iostream>
void function1();
int main(){
fucntion1();
return 0;
}
void fucntion1(){
cout<<"helllo";
}
/*---Stop Cut------------------*/
you only have to declear a function if you use it before you define it
let me know if this doesn't work.
-
thats brill it works
didnt realise that u could do that
thanks alot
pants