I have a file where I'm trying to overload some operators and it's supposed to terminate early given some condition. This file is separate from the main file
#include "MY.h"
// this file is MY.cpp
// MY is a class
int& MY::operator[](int i) {
if (/* condition is met */) exit(1);
else {/* proceed... */}
}
If I compile that, it gives me this error
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status
But let's say I have a main()
with nothing in it, like so:
// same stuff as above code
int main() {}
The new code with an empty main()
function will compile with no complaints.
Now, I have another file and the actual main()
that I want to use is in this file:
#include "MY.cpp"
int main() { /* some code... */}
If I compile this file, it gives me this error:
error: redefinition of 'int main()'
The obvious way to fix this is to get rid of main()
in MY.cpp
, but doing that will give me the first error about a returned 1 exit status (don't even know what that means).
**So the bottom line is this: How can I terminate a function if that function is defined in another file that I'm including in my main file? **