-
function problems
alright, i have a function declared as void, and what it does, it prints stuff out to the screen, now whenever i call this function, i get this error:
implicit declaration of function `int swap(...)'
what the hell does that mean? i copied it directly out of my book
-
-
Code:
#include <iostream.h>
#include <stdlib.h>
int main()
{
int x = 5, y=10;
cout <<"Main. Before swap, x: " <<x<<" y: "<< y<< "\n";
swap(x,y);
cout <<"Main. After swap, x: "<<x<<" y: "<<y <<"\n";
return 0;
}
void swap(int x, int y){
int temp;
cout "Swap. Before swap, x: " << x << " y: "<< y<< "\n";
temp = x;
x = y;
y = temp;
cout << "Swap. After swap, x: "<<x<<" y: "<<y<< "\n";
}
-
You are using a function before it has been declared. Above main add this line.....
void swap(int,int);
This is called a function prototype and tells the compiler the functions return type and parameter list.
-
You can also place the function before main() but with too many functions this can get ugly.