1

What am i doing wrong here?

APP.h

#pragma once

namespace App{

    enum class AppStatus{
    Exit,
    Menu,
    Run
    };

    void frameLoop();

    AppStatus state;

}

App.cpp

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


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

        Graphic::renderingSequence();
    }
}

Errors

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     

Note that my namespace Graphic (declared in \Graphic\Graphic.h) is being recognized by the compiler, even though i declared it just the same way.

Jive Dadson
  • 16,680
  • 9
  • 52
  • 65
stimulate
  • 1,199
  • 1
  • 11
  • 30

1 Answers1

2

stdafx.h (Microsoft precompiled header) must be at the top. This applies to any Visual C++ project with the precompiled headers option turned on, and stdafx.h the standard pch. Those are the default settings for a new project.

Purpose of stdafx.h

The simplest and least error-prone way to define the function within the namespace App is just to put it there.

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();
        }
    }
}
Community
  • 1
  • 1
Jive Dadson
  • 16,680
  • 9
  • 52
  • 65
  • I agree with Jive you should put the function in the namespace rather than saying App::frameLoop(). It might be confusing for people and they might think App is a class. – Lasse Jacobs Dec 16 '16 at 22:55
  • More importantly, the code in the cpp file will automatically resolve names the same as the .h file does. E.g. AppStatus::Exit. – Jive Dadson Dec 16 '16 at 22:58