Re: CFormView adding GetDocument() functionality results in error C2143: syntax error : missing ';' before '*'.
- From: David Wilkinson <no-reply@xxxxxxxxxxxx>
- Date: Thu, 27 Oct 2005 14:29:00 -0400
Computer wrote:
Hi,
My problem started when I added a form, then created a class from the form.
I noticed Document and Debug support missing from the class, so I went ahead and added it.
Now, I get a compile error: "Error C2143: syntax error : missing ';' before '*'. Eminating from "CFormViewDoc* GetDocument() const;
Well, I have seen this error before and added #include "FormViewDoc.h" to the .H file and it compiles just fine.
I don't understand why it can't compile if the
#include "FormViewDoc.h" is in the .CPP file, rather than the .H file?
It works for the other class and the 2 classes are almost exactly the same, besides the difference in the names.
I don't know what the problem could be?
Any Ideas?
I tested this on a brand-spanking new project and get the same results.
Below is the stuff I added, that was missing.
TIA, //--------------------------------------------------------------------------------------------- //Added to the .H file public: CFormViewDoc* GetDocument() const;
//Added to the .H file, below the class definition. #ifndef _DEBUG // debug version in FormViewView.cpp inline CFormViewDoc* CTest::GetDocument() const { return reinterpret_cast<CFormViewDoc*>(m_pDocument); } #endif
//Added to the .CPP file #ifdef _DEBUG #define new DEBUG_NEW #endif
// Added to the .CPP file in the "Test Diagnostics Section". CFormViewDoc* CTest::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFormViewDoc))); return (CFormViewDoc*)m_pDocument; } //---------------------------------------------------------------------------------------------
Regards,,
Computer:
I think you will find, in the cases where it works, that MyDoc.h is included before MyView.h in MyView.cpp. All MFC wizard-generated code depends on this ordering of includes.
IMHO, this is not good practice; if there is something in MyView.h that depends on MyDoc.h, then MyDoc.h should be included in MyView.h.
And also, IMHO, this inlining of the release version GetDocument() is really overkill. Without it, CMyDoc could be introduced by forward declaration in MyView.h.
And also, I thought hiding of non-virtual base class methods, here GetDocument(), was a frowned-upon technique in C++. Personally I usually remove these functions in my CView-derived classes.
Lastly, shouldn't it be
inline CFormViewDoc* CTest::GetDocument() const
{ return static_cast<CFormViewDoc*>(m_pDocument); }not reinterpret_cast.
HTH,
David Wilkinson
.
- Follow-Ups:
- References:
- Prev by Date: Re: command handling in MFC
- Next by Date: OnClose
- Previous by thread: CFormView adding GetDocument() functionality results in error C2143: syntax error : missing ';' before '*'.
- Next by thread: Re: CFormView adding GetDocument() functionality results in error C2143: syntax error : missing ';' before '*'.
- Index(es):
Relevant Pages
|