0

可能重复:
为什么 C++ 编译需要这么长时间?
Visual Studio 2012 编译时间慢

我正在使用visual studio 2012,编译时间很长。仅仅 50 行代码大约需要 20 秒。我认为这是我的计算机故障,但 c# 在它上面编译得很好,而不是 c++。我知道 C++ 需要更长的时间来编译,但 20 秒是荒谬的。

这是我正在尝试编译的代码,编译大约需要 20 秒。

#include<iostream>
using namespace std;

class Entity
{
protected: 
    int health; 
public: 
    void SetHealth(int value)
    {
        health = value;
    }

    void DisplayHealth()
    {
        cout << "Entity: " << health << endl;
    }
};

class Player : public Entity
{
private:
    int xp;
public: 
    void DisplayHealth()
    {
        cout << "Player: " << health << endl;
    }
};

class Enemy : public Entity
{

};

int main()
{
    Player player; 

    Entity *entity = &player;

    entity->SetHealth(10); 
    player.DisplayHealth();

    system("pause");
    return 0;
}
4

1 回答 1

3

我在我安装的 VS2012 下编译了这段代码,用这个唯一的文件构建一个项目大约需要 3 秒。可能是您在安装 VS2012 时遇到了问题。尝试在安全模式下运行它以禁用扩展。

于 2012-10-25T07:51:17.987 回答