Re: CFormView adding GetDocument() functionality results in error C2143: syntax error : missing ';' before '*'.
- From: "Computer" <chollan2@xxxxxxxxxx>
- Date: Thu, 27 Oct 2005 12:23:14 -0700
> 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.
Thanks! It works for the brand-spanking new project, but not mine. Something
else is wrong.
> 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.
Well, 2 in favor of forward declaration, so that is what I am going to do.
> Lastly, shouldn't it be
>
> inline CFormViewDoc* CTest::GetDocument() const
> { return static_cast<CFormViewDoc*>(m_pDocument); }
>
> not reinterpret_cast.
No. It is reinterpret_cast.
It could be a matter of the VS version.
The one I am using is:
Microsoft Development Environment 2002 Version 7.0.9466
Microsoft Visual Studio.NET
Another Question. If I declare something in the .H file. Do I need to
#include in the .H file, or can I put it in the .CPP file?
or, should I just keep adding it, until it stops complaining?
Regards,
"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:eoigKRy2FHA.3592@xxxxxxxxxxxxxxxxxxxxxxx
> 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
>
.
- References:
- Prev by Date: Re: CFormView adding GetDocument() functionality results in error C2143: syntax error : missing ';' before '*'.
- Next by Date: How to send a message?
- Previous by thread: Re: 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
|