Re: CFormView adding GetDocument() functionality results in error C2143: syntax error : missing ';' before '*'.



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

.



Relevant Pages

  • Re: release build failed!!!
    ... I did a quick & dirty console project with your enum. ... It compiles fine with ... VC2005 using default debug and release settings. ... All errors are pointing to a single statement, ...
    (microsoft.public.vc.mfc)
  • Re: Debug mode wont build. Release does.
    ... The settings are Multi-Threaded Debug and Multi-Threaded for Debug and Release respectively. ... It compiles and links in Debug and Release. ...
    (microsoft.public.vc.ide_general)
  • Re: .net cf sp2 problem
    ... Usually when you tell VS to debug it compiles ... > system is Traditional Chinese. ... > White Rong ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: How can I develop in C with VS2005 for Pocket PC??
    ... Ok, I just have substitute in my C code the main function for WinMain, ... Now it compiles with 0 ... when I want to run it or debug it (at the moment I have only some ... yet nothing of Pocket PC) it appears like a pocket pc ...
    (microsoft.public.pocketpc.developer)
  • error with release build
    ... I have a visual studio 2008 asp.net project that compiles fine in debug ... when I switch to release build I get this error: ...
    (microsoft.public.vsnet.general)