Re: Include file semantics?
Add forward declaration
Code:
class CViewSwitchDoc;
into ViewSwitchView.h
Re: Include file semantics?
Quote:
Originally Posted by
VictorN
Add forward declaration
Code:
class CViewSwitchDoc;
into ViewSwitchView.h
Outstanding decipher, the voice of experience speaks.
So then in my novice mind I'm guessing that since #include "ViewSwitchDoc.h" was always in the ViewSwitchView.cpp implementation file, this has kept me from having this before now ?
And now that I'm including the ViewSwitchView.h declaration file somewhere else, it needs the forward declaration to give the compiler a heads up ?
I'm probably just fishing in the wrong ocean on that explanation, but I remember some files I saved on forward declaration information, I will hunt them down and try to educate myself on these ramifications.
Thanks again though, doubt I would have solved this on my own.
Re: Include file semantics?
#include guards belong in the header file, not the CPP.
in ViewSwitchView.h
#ifndef _ViewSwitchView_H_
Body of header file goes here
#endif
Re: Include file semantics?
Your ViewSwitchView.h contains the declaration of
Code:
CViewSwitchDoc* GetDocument() const;
But compiler while compiling MainFrm.cpp, which also includes ViewSwitchView.h, has no idea what CViewSwitchDoc is.
So you can either add
Code:
#include "ViewSwitchDoc.h"
to MainFrm.cpp (before the
Code:
#include "ViewSwitch.h"
or add the forward declaration into the ViewSwitchDoc.h.
Re: Include file semantics?
Quote:
Originally Posted by
GCDEF
#include guards belong in the header file, not the CPP.
in ViewSwitchView.h
#ifndef _ViewSwitchView_H_
Body of header file goes here
#endif
I like that even better, now the includers (the cpp files) don't even have to worry with it, since it's covered right in the original header. I've never seen this method before, thanks.
Quote:
Originally Posted by
VictorN
Your
ViewSwitchView.h contains the declaration of
Code:
CViewSwitchDoc* GetDocument() const;
But compiler while compiling
MainFrm.cpp, which also includes
ViewSwitchView.h, has no idea what
CViewSwitchDoc is.
So you can either add
Code:
#include "ViewSwitchDoc.h"
to
MainFrm.cpp (before the
Code:
#include "ViewSwitch.h"
or add the forward declaration into the
ViewSwitchDoc.h.
Ah yes, that zeros in on exactly what's going down while the compiler is focusing on the MainFrm.cpp file. Thanks again.