C++对main的多重定义

C++ Multiple definition of main

本文关键字:定义 main C++      更新时间:2023-10-16

(抱歉英语不好)嗨,伙计们!我的程序不想运行,因为一个错误,谢谢你好心帮助我。

我的来源:

main.cpp

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <string>
#include <vector>
#include "function_h.h"
using namespace std;
int main()
{
    int reponse(0);
    ifstream myfile("dico.txt");
    cout << "1. Mode solo | 2. Mode multi" << endl;
    cout << "> ";
    cin >> reponse;
    if (reponse > 0 || reponse < 3)
    {
        cin.ignore();
        if (reponse == 1)
        {
        }
    } else { cout << "Une reponse valide." << endl; }
}

函数.cpp

#include "main.cpp"
#include "function_h.h"
using namespace std;
string Melange(string mot)
{
    int position(0);
    string result;
    while (mot.size() != 0)
    {
        result += mot[position];
        mot.erase(position, 1);
    }
    return result;
}

函数_h.h

#ifndef FUNCTION_H_H_INCLUDED
#define FUNCTION_H_H_INCLUDED
using namespace std;
string Melange(string mot);
#endif

错误

感谢

问题就在这里:

#include "main.cpp"

通常,您不希望(需要)在任何地方包含.cpp文件(编译单元)(除非您希望包含外部模板类定义)!