2

可能重复:
未定义对“WinMain@16”的引用

我正在构建一个应用程序,该应用程序根据用户确定的估计旅行速度计算从预定城市到达用户选择的目的地所需的旅行时间。对于这个程序,我将使用类/类源文件。在编译我的源文件时,我不断收到错误“未定义对 `WinMain@16' 的引用”,由于我不熟悉源文件的用法,我不确定如何解决这个问题。对于正确使用源文件的正确方向,任何帮助将不胜感激。在此先感谢您的帮助。

头文件:

 #include <iostream>

    using namespace std;

    class Trip
    {
        private:
            string destination;
            double distance;

        public:
            void TripValue(string b, double c);
            void TripTime(Trip *a);
    };

源文件:

#include "Trip.h"
#include <iostream>

using namespace std;

void Trip::TripValue(string b, double c)
{
    destination = b;
    distance = c;
}

void Trip::TripTime(Trip *a)
{
    double user_speed;
    double time;

    cout << "Please enter your estimated travel speed in miles per hour: ";
    cin >> user_speed;
    cout << endl;

    time = (a->distance / user_speed);

    cout << endl;
    cout << "Your estimated travel time to " << a->destination << " is "
        << time << " hours.\n";
    cout << endl;
}

申请代码:

#include <iostream>
#include "Trip.h"

using namespace std;

int main()
{
    Trip StL, Indy, Det, Nash, Dal, Den, NY, LA, Mia, Sea;

    int choice;

    StL.TripValue("St. Louis", 297.34);
    Indy.TripValue("Indianapolis", 184.78);
    Det.TripValue("Detroit", 282.73);
    Nash.TripValue("Nashville", 441.02);
    Dal.TripValue("Dallas", 925.91);
    Den.TripValue("Denver", 1004.93);
    NY.TripValue("New York", 791.50);
    LA.TripValue("Los Angeles", 2017.74);
    Mia.TripValue("Miami", 1363.55);
    Sea.TripValue("Seattle", 2032.31);

    do
    {
        cout << "=================================Trip Calulator=================================\n";
        cout << "Select your destination from Chicago:\n";
        cout << endl;
        cout << " 1. St. Louis\n";
        cout << " 2. Indianapolis\n";
        cout << " 3. Detroit\n";
        cout << " 4. Nashville\n";
        cout << " 5. Dallas\n";
        cout << " 6. Denver\n";
        cout << " 7. New York\n";
        cout << " 8. Los Angeles\n";
        cout << " 9. Miami\n";
        cout << "10. Seattle\n";
        cout << endl;
        cout << " 0. Exit\n";
        cout << "================================================================================\n";

        cin >> choice;

        cout << endl;

        switch (choice)
        {
            case 1:
                StL.TripTime(&StL);
                break;
            case 2:
                Indy.TripTime(&Indy);
                break;
            case 3:
                Det.TripTime(&Det);
                break;
            case 4:
                Nash.TripTime(&Nash);
                break;
            case 5:
                Dal.TripTime(&Dal);
                break;
            case 6:
                Den.TripTime(&Den);
                break;
            case 7:
                NY.TripTime(&NY);
                break;
            case 8:
                LA.TripTime(&LA);
                break;
            case 9:
                Mia.TripTime(&Mia);
                break;
            case 10:
                Sea.TripTime(&Sea);
                break;
        }
    } while (choice != 0);
}
4

1 回答 1

1

Thats a linker problem.

Try to change Properties -> Linker -> System -> SubSystem

from Windows (/SUBSYSTEM:WINDOWS) to Console (/SUBSYSTEM:CONSOLE)

于 2012-10-08T04:26:06.173 回答