I make one program for the experiment and there was one mistake. Made a new project and left the same function and the same properties, but the error remained, what could be the matter? Error: the function "int main (void)" already has implementation text ( C2084 )

Source.cpp

#include <iostream> #include <Windows.h> #include "func.h" using namespace std; void Interface(); int main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); Interface(); } 

func.h

 #pragma once #include "Source.cpp" void Interface() { int quest; while (true) { cout << "1. Открыть базу" << endl; cout << "2. Закрыть программу" << endl; cout << "Номер пути _\b"; cin >> quest; if (quest = 1) { cout << "Открыто!"; } else if (quest = 2) { cout << "Закрыто!"; } } } 
  • one
    why do you connect the .cpp file? - pavel

1 answer 1

You have a wrong understanding of what should be in the header file, and what should be in .cpp .

Place the declarations in the header file, and the definitions in the cpp file. In the header file are also inline-implementations, templates, etc. things, but in your case, all that should be placed in func.h is

 void Interface(); 

Everything else is in .cpp files, and do not include .cpp files using the #include directive - otherwise you get a violation of the rules of one definition .

  • 3
    "Place the declarations in the header file, and the definitions in the cpp file." - and how, for example, class definitions in headings? I think the wrong approach is “remember what should be in .h and what in .cpp” - Croessmah
  • 2
    @Croessmah I think that without a certain simplification, to give a standard and long definitions right away is wrongly didactic. You can study electricity and magnetism, starting with Maxwell’s equations, but usually they first talk about ebony sticks and wool pants :) - Harry
  • In fact, there is probably a misunderstanding of the preprocessor's work. Specifically, the #include directive is replaced with the contents of the specified file. And the tips that where to post is directly misleading. - VTT
  • 2
    @VTT Sorry, I just got unhelpful criticism. Do you think the answer is incorrect? No questions, let's yours. And it turns out, as in that saying - "I do not know how, but I know what is wrong." As you understand, I (like you) can write a program that violates my own advice and that will be compiled. Should I give it as a sample, how to write programs? You do not find that if a person asks such a question, then he must first be taught to let the more stringent, but safer working rules? And then, when he figured out what was what, he himself would understand what was what. - Harry