I was trying to compile the following code in cygwin using g++:
------------------------------------------
#include <iostream>
using namespace std;
int identity(int input)
{
int output = input;
return output;
}
------------------------------------------
I get this error:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.25-1/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain@16'
collect2: error: ld returned 1 exit status
#include <iostream>
using namespace std;
int main()
{
int identity(int input);
int output = input;
return output;
}
But now I get this error:
bh.cpp: In function �int main()�:
bh.cpp:12:18: error: �input� was not declared in this scope
int output = input;
^
This is my first programming class, sorry if I am missing something obvious. My teacher tells me to find out what this program does. At school we use different operating system and a Unix terminal. I am using Cygwin on Windows vista.
Again, the compiler is not asking you to jam random things into the middle of your code when it says main doesn't exist. It's asking you to add main(), unrelated to your code, outside it.
Of course, if you want your function to be run, you should tell main() to run it, since main runs everything.
#include <iostream>
using namespace std;
// Your function
int identity(int input)
{
int output = input;
return output;
}
// The function which the compiler will call when the program is run
int main() {
int output=identify(32);
}
At first I got another error, but I realized you used "identify" instead of "identity", so that's fixed. Anyway, the output is nothing when I run ./bh.exe(the filename of this code). Is this correct?
It does nothing you can see from the outside, so yes, that is correct.
You would benefit from reading one of the many basic tutorials on getting started with C or C++. Based on your code I'd say look for C++ tutorials. I hope that is what your class is about.