C++致命错误LNK1120:1个未解决的外部引用

23

这个错误是什么原因造成的?我谷歌了一下,发现前几个解决方案都说库或主函数有问题,但在我的情况下它们似乎都没问题,我甚至重新打了一遍!可能是什么原因导致的呢?

这可能有所帮助:

MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol WinMain@16 referenced in function __tmainCRTStartup

#include <iostream>
using namespace std;
int main()
{
    const double A = 15.0, 
                 B = 12.0, 
                 C = 9.0;
    double aTotal, bTotal, cTotal, total;
    int numSold;

    cout << "Enter The Number of Class A Tickets Sold: ";
    cin >> numSold;
    aTotal = numSold * A;

    cout << "Enter The Number of Class B Tickets Sold: ";
    cin >> numSold;
    bTotal = numSold * B;

    cout << "Enter The Number of Class C Tickets Sold: ";
    cin >> numSold;
    cTotal = numSold * C;

    total = aTotal + bTotal + cTotal;

    cout << "Income Generated" << endl;
    cout << "From Class A Seats $" << aTotal << endl;
    cout << "From Class B Seats $" << bTotal << endl;
    cout << "From Class C Seats $" << cTotal << endl;
    cout << "-----------------------" << endl;
    cout << "Total Income: " << total << endl;

    return 0;
}

发布完整的错误信息。哪个是未解决的符号? - K-ballo
未解析的符号是什么?请提供完整的错误文本。 - Lou
你还应该会得到 LNK2001 错误列表,列出了未解决的内容。那些是什么? - shf301
13个回答

0
在我的情况下,我完全忘记添加main()函数了。

0
在我的情况下,当我将一个函数声明为“public”访问限定符时,就会出现这个错误。当我将该函数声明为“private”时,问题得到了解决。

0

我遇到了同样的错误。对我来说,原因是我尝试在.cpp文件中实现一个内联函数,而不是将其放在定义所在的头文件中。因此,当我尝试包含头文件并使用该函数时,就会出现这个错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接