main的多重定义,首先在devc ++中定义

时间:2017-03-12 00:07:01

标签: c++

我只是c ++的初学者我正在使用devC ++。我在项目中有两个单独的文件,但是当我运行第二个文件时,它会显示一条错误消息:

test.cpp:(.text+0x0): multiple definition of `main' first defined here). 

您能否详细解释清楚如何改变如何做到这一点。

很抱歉重复这个问题,因为我已经缺乏了解,如果有详细的答案,请提供链接。

这是我的两个文件:

prblm2.cpp

#include<iostream>
using namespace std;
int main()
{
    const double artificial_sweetner=0.001;
    double mouse_weight, friend_weight, die, number_of_soda_pop; 
    cout<<"type in the weight of the mouse and your freinds target weight"<<endl;
    cin>>mouse_weight>>friend_weight;

    while (mouse_weight>0 && friend_weight>0)
    {
        die=(friend_weight/mouse_weight)*artificial_sweetner;
        number_of_soda_pop=die/artificial_sweetner;
        cout<<"the number of soda your freind can drink is "<<number_of_soda_pop<<endl;
        cout<<"type in the weight of the mouse and your freinds target weight"<<endl;
        cin>>mouse_weight>>friend_weight;
    }

}

TEST.CPP

#include<iostream>
using namespace std;
int main() 
{
    int i;
    for(i=1;i<10;i++)
    {
        for(i=1;i<10;i++)
        {
            for(i=1;i<10;i++)
            {
                cout<<"*"<<endl;
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您的问题是您有两个<table><tr> <td rowspan=2>tall<br>tall<br>tall<br>tall<br> <td valign="top">top</td> </tr><tr> <td valign="bottom">bottom</td> </tr></table> 功能。该标准不允许此类计划。解决方案是只有一个main

例如:

此程序不正常,因为main函数太少:

main

此程序不正常,因为void foo(){} 函数太多:

main

这个程序格式正确,并且具有恰当数量的int main(){} int main(){} 函数:

main