0

已解决我的“WorkoutGeneratorMain.cpp”被 IDE 归类为 C++ 头文件。我不知道为什么会这样,但我修复了它。现在我要处理我所有的其他错误。

谢谢大家!

==================================================== =

在 Visual Studio 2010 Professional 中编译我的程序时出现以下错误:

------ 构建开始:项目:WorkoutGenerator,配置:调试 Win32 ------
构建开始于 2012 年 8 月 15 日下午 12:19:18。
InitializeBuildStatus:
  触摸“Debug\WorkoutGenerator.unsuccessfulbuild”。
ClCompile:
   LiftClass.cpp
ManifestResourceCompile:
   所有输出都是最新的。
MSVCRTD.lib(crtexe.obj) : 错误 LNK2019: unresolved external symbol main referenced in unction _ _tmainCRTStartup
C:\Users\Shanalex\Documents\Programming\C++Programming\WorkoutGenerator\WorkoutGenerator\Debug\WorkoutGenerator.exe:致命错误 LNK1120 : 1 未解决的外部问题

在我的搜索中,我找到了几个解决此问题的指南;但是,他们几乎都建议该文件是设置为控制台设置的 Windows 应用程序,反之亦然。我的程序是一个控制台应用程序,所有设置对于一个 win32 控制台应用程序来说似乎都是正确的。有些地方存在链接错误,但我的项目设置似乎没有其他人有的任何问题。

我对 C++ 和 VS2010 中的多部分程序相当陌生。我很容易犯一个基本错误,但是在将我的代码与各种教程和书籍的代码进行比较时,我无法找到它。

我有三个代码文件,如下:

电梯类.h

//Lift Classes
//Defines the Lift Class


#ifndef LIFTCLASSHEADER_H_INCLUDED
#define LIFTCLASSHEADER_H_INCLUDED

#include <iostream>
#include <string>
#include <vector>
#include <random>
#include <ctime>

using namespace std;

class Lift
{
public:
    string LName;
    string LType;
    string LBody;
    vector<double> LLoadScale;

    Lift(string Name, string Type, string Body, 
        double Pawn, double Bishop, double Knight, double Rook, double Royal);
};

Lift::Lift(string Name, string Type, string Body, 
    double Pawn, double Bishop, double Knight, double Rook, double Royal)
{
    LName = Name,

    LType = Type,

    LBody = Body,

    LLoadScale.push_back(Pawn),
    LLoadScale.push_back(Bishop),
    LLoadScale.push_back(Knight),
    LLoadScale.push_back(Rook),
    LLoadScale.push_back(Royal);
}


#endif

然后,我有电梯类的 .cpp 实现,以及随机化它们的函数。

电梯类.cpp

//Exercise Randomizer using Lift Class
//Initializes Lifts for use in Workout Generator
//Version 2.0 will reference Database

#include "LiftClass.h"

Lift exerciseRandomizer() //Define database of exercise & randomly select one
{    
    vector<Lift> LiftDatabase;

    Lift Clean("Clean", "Olympic", "Full", .33, .66, 1, 1.33, 1.66);
    Lift Bench("Bench Press", "Heavy", "Upper", .33, .66, 1, 1.5, 2);

    LiftDatabase.push_back(Clean);
    LiftDatabase.push_back(Bench);

    srand(static_cast<unsigned int>(time(0))); //Seed random number

    unsigned randomNumber = rand(); //Generate Random Number

    //Get random between 1 and total lift count
    unsigned randomSelector = (randomNumber % LiftDatabase.size()); 

    return LiftDatabase[randomSelector];
}

最后,我有我的主要功能 WorkoutGeneratorMain.cpp

WorkoutGeneratorMain.cpp

//Workout Generator
//Generates workouts based on goal and fitness level

#include "LiftClass.h"


int main()
{
    exerciseRandomizer();

    Lift LiftA = exerciseRandomizer();

    cout << "\n\nYour first lift is: " << LiftA.LName << "\n\n Its lift type is: " << LiftA.LType << endl;
    cout << "\n\nGood Luck!" << endl;

    system("pause");
    return 0;
}

非常感谢任何建议。

谢谢,

-亚历克斯

4

1 回答 1

3

你会认为这int main()是可执行文件的入口点,但它不是(必然)。:) 根据项目设置,运行时可能会调用wmainmain。这就是您改用它的原因_tmain,它是一个扩展到运行时期望的宏。

尝试将其更改为:

int _tmain(int argc, _TCHAR* argv[])

PS - 这应该是自动生成的,也许你删除了它而不是替换_tmain.

于 2012-08-15T18:22:08.113 回答