C ++主定义 [英] C++ Multiple definition of main

查看:165
本文介绍了C ++主定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(对不起英语)
嗨家伙!
我的程序无法运行,因为一个错误,谢谢你,请帮助我。

(Sorry for bad english) Hi guys ! My program doens't want to running because an error, thank you kindly help me.

我的来源:

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; }

}

function.cpp / p>

function.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;
}

function_h.h
$ b

function_h.h

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

#endif

错误

谢谢

推荐答案

问题出在这里:

#include "main.cpp"

通常你不想要(需要)包括 .cpp 单位)(除非您想要包含外部模板类定义)!

Usually you don't want (need) to include .cpp files (compilation units) anywhere (unless you want to include externed template class definitions)!

这篇关于C ++主定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆