Error C2084 'Function already has a body'
c++, visual-c++
Solution
OP:
I am intending it to hold all the string and console manipulation functions for the entire game, so almost every file in the program has it included
And this is the problem. Its a `.cpp` file not a `.h`. It actually contains definitions of symbols. If you now include this file, its verly likely that some other files, you also include, include this file aswell.
What happens is that in the preprocessed unit code like this occur:
void clear_console()
{
if (system("CLS")) system("clear");
}
void clear_console()
{
if (system("CLS")) system("clear");
}
The error message makes sense now, doesnt it? To solve this you will have to use a header guard
Or better, fix your file structure: A `.cpp` should never be included. Instead create a header file with e.g this declaration `void clear_console();`. In a `.cpp` you then implement the function like you did already, but you only include the header (`.h`) file.
Also notice that this isnt possible with anonymous namespace, but they dont make any sense at all here. So just use a regular / named namespace or get rid of it.
Problem
I am a novice at C++ coding and this is my first post on Stack Overflow. I am coding a text based game in Visual C++ and I have been getting the C2084 error in this file: ``` //game_system_functions.cpp #include "basicdefines.h" namespace { using namespace std; void clear_console() { if (system("CLS")) system("clear"); } } ``` I find this odd, because it is only happening in This File. All the other .cpp files have no problem with functions and they are all in a similar format. I have checked and double checked all my code, and there is no other function called clear_console. I have tried renaming the function to a bunch of random letters, and I still get the same error. Other functions in the same .cpp file get a similar error. This issue has been bothering me for the past week, and I can't solve it. I have read other posts about `error C2084` and they aren't having this problem. I would appreciate some help regarding this error. Thank you. P.S. I apologize about any formatting problems, as I said earlier in the post, this is my first time posting on stack overflow and sorry if the title is a little undescriptive.