views:

192

answers:

4

So some reason, my .cpp file is missing it's header file. But I am not including the header file anywhere else. I just started so I checked all the files I made

enginuity.h

#ifndef _ENGINE_
#define _ENGINE_

class Enginuity
{

public:
    void InitWindow();

};

enginuity.cpp

#include "Enginuity.h"


void Enginuity::InitWindow()
{

}

main.cpp

#include "stdafx.h"
#include "GameProject1.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name

// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{

code.....
#endif

dont know what's going on. The error I get is

1>c:\users\numerical25\desktop\intro todirectx\gameproject\gameproject1\gameproject1\enginuity.cpp(1) : warning C4627: '#include "Enginuity.h"': skipped when looking for precompiled header use
1>        Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\numerical25\desktop\intro todirectx\gameproject\gameproject1\gameproject1\enginuity.cpp(8) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
+5  A: 

Did you read the error message?

fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

I don't see an #include "stdafx.h" in enginuity.cpp. ;) If you're using precompiled headers, you need to include the precompiled header in every source (.cpp) file.

Billy ONeal
Makes me miss being a teaching assistant. "I'm getting the error 'unexpected end of line; possible missing semicolon', what should I do?" "Well...are you missing a semicolon?" "Oh yeah!"
Michael Mrozek
I tried to add it in my header but I I still got the error. I didn't know it had to be in the .cpp file or even all .cpp files at that. I am getting confused about pre compiled headers. I thought that once a header is included in a file once. It can no longer included again???
numerical25
@num It can be, although you usually don't want it to be. It's not included in `enginuity.cpp` though, just `main.cpp`
Michael Mrozek
Ok, so what about the pragma once. I thought that when that is implemented in a header, the header is only included the first time it's called ?? If I put stdafx.h in all my .cpp files. Wouldnt stdafx.h be ignored by all other files except for the first one that calls it??
numerical25
The #include "stdafx.h" needs to be the very first thing in every .cpp file.
JohnMcG
@num No, you can (and must) include it in every cpp file. The only thing `#pragma once` or header guards do is stop you from including a header twice in the same cpp file
Michael Mrozek
A: 

Add #include "stdafx.h" to the top of enginuity.cpp or disable precompiled headers in your project.

George
+1  A: 

You'll either want to put the line

#include "stdafx.h"

at the top of all your .cpp files (in this case, enenuity.cpp is the only one missing it.

or disable precompiled headers in your project.

If you have precompiled headers enabled in your project, Visual C++ will look for that #include directive at the top of all your source files. If it's not there, you'll get the negative commentary you received.

JohnMcG
+1  A: 

Your header file, enginuity.h is missing a #endif, or is there a mistake in the posting?

Thomas Matthews