Well at least it will give the OP an idea of what it should look like, to start with. |
Discussion
If the OP doesn't know what a program containing two cpp files and an h file should look like, he should dump the IDE and do it by hand until he does know what it looks like. In the case above, the OP clearly does not know what it should look like and as such has managed to have the exact same function defined in two separate cpp files, causing this link error.
He also clearly does not understand the process by which source code compiles to object code links to binary executables/libraries; if he did, he'd know how to fix this link error. Again, this is only possible because people use IDEs without understanding what they're doing.
Explanation of problem
In this case, the compiler sees two cpp files to compile. One called window.cpp, which contains function
int ChooseMessage()
. This cpp file is compiled into a binary object.
Then, COMPLETELY SEPARATELY (because that's how it works) the cpp file Main.cpp is compiled, and it contains function
int ChooseMessage()
.
Include guards are irrelevant here. When it gets to them, it checks to see if it has already included the file IN THIS CPP FILE. There is no knowledge of what happened in the other cpp file, which is entirely correct and the right thing to do. This cpp file is compiled into a binary object.
Then, the linker tries to join together these two binary objects. It lokos through them for the function
int ChooseMessage()
and finds it TWICE! It does not know which one you mean to use, so it throws an error and halts.