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



> 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
>


.



Relevant Pages

  • Re: CodeFile - or a bug in VS?
    ... CodeFile should be generated isntead of the CodeBehind attribute. ... That's OK...and will compile without problems. ... If you create a new Web Project, the page declaration looks like this: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Defining variable in C header file related doubt
    ... And it didn't compile, obviously. ... with int g declared in both files (and apparently ... "An external def1nition is an external declaration that is also a ... If an identif1er declared with external linkage is used in an ...
    (comp.lang.c)
  • Re: Syntax directed compilation
    ... seems to be "too much power, users write their own languages and then ... The declaration statements are executed ... compile time. ... is also a statement which is executed at compile time. ...
    (comp.compilers)
  • Re: Implicit int
    ... compile or implement, or even would have been in the 1970s. ... note that if you can't declare an array of size "n", ... could not already do with long int, had they chosen so to do. ... I recognise that this is not a popular view, but if the declaration is ...
    (comp.std.c)
  • Re: Sendmail Core Dumps and Compiling Sendmail 8.11.7 on AIX 5.2 ml6
    ... Sendmail Core Dumps and Compiling Sendmail 8.11.7 on AIX 5.2 ml6 ... I'm using the IBM C compiler and gcc. ... If I try and compile with the IBM C compiler I get the following messages ... from previous declaration on line 267 of "/usr/include/stdio.h". ...
    (AIX-L)