![]() |
| | #1 | |
| Super Moderator Join Date: Aug 2001
Posts: 7,817
| MFC include BS However the include stuff is a gigantic mess. So I went to edit some of it and now I have well over 1250 errors and no way to fix any of it. In a C++ program correct me if I'm wrong but all headers needed for the CPP file should be in the respective header. But in MFC the frieking includes are in the damned CPP file? Why? And now I have a dialog (CLayersDlg.h) that needs to include CMainFrm.h, but the CMainFrm.h must also include CLayersDlg.h. But when I do this, the stupid compiler tells me that basically this is undefined: Code: #include "CLayersDlg.h" ... CLayersDlg LayersDlg; So why does this not work? MainFrm.h Code: #if !defined(AFX_MAINFRM_H__F76A4064_27DD_4BB7_A85E_0FD7771C3730__INCLUDED_)
#define AFX_MAINFRM_H__F76A4064_27DD_4BB7_A85E_0FD7771C3730__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <io.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <vector>
//Core include
#include "ZeldaEditor.h"
//User includes
#include "LayersDlg.h" //Active layers dialog
//#include "MapProject.h" //Project->New response dialog
//#include "Tiles.h" //Tile tool dialog(s)
//#include "CResourceFile.h" //Resource file class
//#include "TileManager.h" //Tile manager class
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
// Attributes
public:
// Operations
public:
//friend class CZeldaEditorDoc;
bool bProjectReady;
bool bResourceFileLoaded;
//Active layers dialog
LayersDlg dlgLayers;
....
Quote:
What the heck is going on and how can I fix this include hell? I need the CMainFrame class quite often for my dialogs so I need to include it so I can do this: CMainFrame *ptrFrame=(CMainFrame *)AfxGetMainWnd(); ptrFrame->DoSomethingInCMainFrameClass(); I don't want a pointer to the actual MFC class, but I want a pointer to my derived class which is why I need to include CMainFrm.h All this is really making me...um...mad. And since my project is over 4K lines......I'm really mad now that I tried to add one thing and the whole program came crashing to its knees. Same issue. Included a header file so I could use it's class data type in a class header file and it said the damned thing was undefined. Unbelievable. I know what it is doing but I don't know why. It is saying that it is undefined because even though I put #include<some_header>, some_header has already been included and so it doesn't include it. But if some_header has already been defined then some_header inside of <some_header.h> should also be already defined. So doing this should work: SomeObject.h Code: #ifndef SOMEOBJECT
#define SOMEOBJECT
class SomeObject
{
};
#endif
Code: #ifndef SOMECLASS
#define SOMECLASS
#include "SomeObject.h"
class SomeClass
{
SomeObject Object;
...
};
__________________ If you aim at everything you will hit something but you won't know what it is. Last edited by Bubba; 10-29-2005 at 03:49 AM. | |
| Bubba is offline | |
| | #2 |
| Super Moderator Join Date: Aug 2001
Posts: 7,817
| I fixed it by just dumping the pre-compiled headers. Somehow the PCH file got messed up and was causing lots of issues. Bad MS, bad.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #3 |
| Registered User Join Date: Aug 2001 Location: Newport, South Wales, UK
Posts: 1,094
| I don't see why precompiled headers are all that necessary to be enabled by default, we've left the days of 50 MHz 486's behind, most compilation jobs take a few minutes at best and all PCH does is shave a few seconds off. It's not like I've ever heard of programmers being tied to the clock like call centre peeps ("Compile this in 35 seconds or you're fired!")... ![]() But yes Bubba, if you use MFC in a big program you are gonna have to deal with little problems like that. Call it a learning experience. |
| SMurf is offline | |
| | #4 |
| Super Moderator Join Date: Aug 2001
Posts: 7,817
| Oh and any suggestions on serialization? My editor saves and loads tile maps along with tile resource files (former BMPs, header removed and replaced with my own pertinent info, and RLE compressed RGB data). The streaming method for MFC doesn't really fit my needs so I wrote my own save file functions. Bad practice? Should I always use Serialize()?
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #5 | |
| Registered User Join Date: Aug 2005
Posts: 1,265
| you only really need to use serialize() if you want to serialize MFC objects. Otherwise, if you are just writing/reading your own non-MFC objects you can do your own thing outsize CArchive and CFile. Quote:
Precompiled headers are not unique to Microsoft compilers. The last time I was on GNU.org there was some comments about g++ also using them. I don't know how wide-spread that idea has become. | |
| Ancient Dragon is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Abnormal Program Termination when executed from C:\Program Files\... | m37h0d | Windows Programming | 48 | 09-26-2008 03:45 AM |
| process programming | St0rM-MaN | Linux Programming | 2 | 09-15-2007 07:53 AM |
| to #include or not to #include | krygen | C++ Programming | 9 | 12-25-2004 12:06 AM |
| Classes inheretance problem... | NANO | C++ Programming | 12 | 12-09-2002 03:23 PM |
| what do I have to include for mfc app | awarden | Windows Programming | 4 | 05-25-2002 06:45 AM |