"StdAfx.h" :
#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include "globals.h"
#include "CGEutils.h" // <- this file has functions that I want to use over my whole project
"file.cpp" :
#include "StdAfx.h"
// but in this file I can''t use the functions from "CGEutils.h"
// unless I add #include "CGEutils.h" in this file too
#include "StdAfx.h"
How come when I include a header file in "StdAfx.h" and then include "StdAfx.h" in a cpp-file he doesn''t find functions from the first header-file
like this :
Do you get a linker error or a compiler error? And I am hoping that you still have the
line intact at the end of the stdafx.h
#endif //AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
line intact at the end of the stdafx.h
yes that last line was included, I just didn''t paste it
I get a compile error :
error C2065: ''Write2Log'' : undeclared identifier
so he doesn''t know this function, right?
although it should be known since I included "StdAfx.h" and in "StdAfx.h" I have the line : #include "CGEutils.h"
so what am I doing wrong?
I get a compile error :
error C2065: ''Write2Log'' : undeclared identifier
so he doesn''t know this function, right?
although it should be known since I included "StdAfx.h" and in "StdAfx.h" I have the line : #include "CGEutils.h"
so what am I doing wrong?
I always thought you had to put your includes after stdafx
I don''t like to use precompiled headers though.
I don''t like to use precompiled headers though.
quote: Original post by Maega
I always thought you had to put your includes after stdafx
I''m pretty sure you do.
Maega:
"I always thought you had to put your includes after stdafx "
I dont see anything about him putting the stdafx after any include file.
Da Cobra:
Why dont you check these:
- Does the file compile when you include the headers in the file instead of stdafx.h ( remove the headers from stdafx )
- Are the header files properly encapsulated . i.e. CGEutils.h should be like
- Finally, is the function syntax in your header file correct
Oztan
"I always thought you had to put your includes after stdafx "
I dont see anything about him putting the stdafx after any include file.
Da Cobra:
Why dont you check these:
- Does the file compile when you include the headers in the file instead of stdafx.h ( remove the headers from stdafx )
- Are the header files properly encapsulated . i.e. CGEutils.h should be like
#ifndef _INC_CGEUTILS_#define _INC_CGEUTILS_blah Write2Log ( blah );#endif
- Finally, is the function syntax in your header file correct
Oztan
my file does compile right if I also include "CGEutils.h"
but shouldn''t that also be the case if I include "CGEutils.h" in "StdAfx.h"
I can go on with programming, but I''m just curious why it doesn''t compile this way?!?
but shouldn''t that also be the case if I include "CGEutils.h" in "StdAfx.h"
I can go on with programming, but I''m just curious why it doesn''t compile this way?!?
Umm you do have a line break between the two includes right ?''
as in:
#include "globals.h"
#include "CGEutils.h"
and not:
#include "globals.h"#include "CGEutils.h"
as in:
#include "globals.h"
#include "CGEutils.h"
and not:
#include "globals.h"#include "CGEutils.h"
If you have 2 files that is dependent of each other, ake a prototype of the function/object that is undefined.
file1.h uses CFile2 class in file2.h
and
file2.h uses CFile1 class in file1.h
Then in stdafx you would put this in:
#include "file1.h"
#include "file2.h"
File1.h would fail since that file dont know about CFile2 which is defined in file2.h. So, what you need to do is to tell File1 that CFile2 will be declared later with a "prototype".
ie:
class CFile2;
#include "file1.h"
#include "file2.h"
Now file1.h knows there is a class named CType2 somewhere. There is two solutions to this, either you put all prototypes in the file where you need them. Ie put the line "class CFile2;" in top of file1.h. Or make a global prototype.h which contains prototypes of all classes/functions.
ie;
Prototypes.h :
// Class prototypes
class CFile1;
class CFile2;
class CFile3;
// Function prototypes
extern void HelloWorld( void );
And then just make sure you include the prototypes.h file before all class/function definitions.
file1.h uses CFile2 class in file2.h
and
file2.h uses CFile1 class in file1.h
Then in stdafx you would put this in:
#include "file1.h"
#include "file2.h"
File1.h would fail since that file dont know about CFile2 which is defined in file2.h. So, what you need to do is to tell File1 that CFile2 will be declared later with a "prototype".
ie:
class CFile2;
#include "file1.h"
#include "file2.h"
Now file1.h knows there is a class named CType2 somewhere. There is two solutions to this, either you put all prototypes in the file where you need them. Ie put the line "class CFile2;" in top of file1.h. Or make a global prototype.h which contains prototypes of all classes/functions.
ie;
Prototypes.h :
// Class prototypes
class CFile1;
class CFile2;
class CFile3;
// Function prototypes
extern void HelloWorld( void );
And then just make sure you include the prototypes.h file before all class/function definitions.
Domine non secundum peccata nostra facias nobis
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement