1

我在这里做错了什么?

应用程序.h

#pragma once

namespace App{

    enum class AppStatus{
    Exit,
    Menu,
    Run
    };

    void frameLoop();

    AppStatus state;

}

应用程序.cpp

#include "App.h"
#include "stdafx.h"
#include <Graphic\Graphic.h>


void App::frameLoop()
{
    while (state != AppStatus::Exit) {

        Graphic::renderingSequence();
    }
}

错误

Error   C2653   'App': is not a class or namespace name App 
Error   C2065   'state': undeclared identifier  App 
Error   C2653   'AppStatus': is not a class or namespace name   App 
Error   C2065   'Exit': undeclared identifier   App     

请注意,我的命名空间Graphic(在 \Graphic\Graphic.h 中声明)正在被编译器识别,即使我以同样的方式声明它。

4

1 回答 1

2

stdafx.h(Microsoft 预编译头文件)必须位于顶部。这适用于任何打开了预编译头选项并且 stdafx.h 是标准 pch 的 Visual C++ 项目。这些是新项目的默认设置。

stdafx.h 的目的

在命名空间 App 中定义函数的最简单和最不容易出错的方法就是把它放在那里。

APP.CPP

#include "stdafx.h" // Nothing goes above this
#include "App.h"
#include <Graphic\Graphic.h>

namespace App {
    void frameLoop()
    {
        while (state != AppStatus::Exit) {
            Graphic::renderingSequence();
        }
    }
}
于 2016-12-16T22:36:45.380 回答