Hi guys,

I have compiler error:
"c:\components\in-process\connectablecomponent\stdafx.cpp(5) : error C2850:
'PCH header file' : only allowed at file scope; may not be in a nested
construct"

It points to stdafx.cpp.
How to solve this ?

thank you
Vilius

Re: Annoying compiler error ? by Scott

Scott
Tue Oct 24 16:43:27 CDT 2006

Vilius wrote:
> Hi guys,
>
> I have compiler error:
> "c:\components\in-process\connectablecomponent\stdafx.cpp(5) : error C2850:
> 'PCH header file' : only allowed at file scope; may not be in a nested
> construct"
>
> It points to stdafx.cpp.
> How to solve this ?
>
> thank you
> Vilius
>
>

Do you understand the way the precompiled header feature works? Check
your stdafx.cpp file. Nothing except comments may preceed the

#include "stdafx.h"

--
Scott McPhillips [VC++ MVP]


Re: Annoying compiler error ? by Vilius

Vilius
Tue Oct 24 17:20:30 CDT 2006

I never edited stdafx.cpp since it was created by wizard.

"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:%235dD%23V79GHA.1168@TK2MSFTNGP03.phx.gbl...
> Vilius wrote:
>> Hi guys,
>>
>> I have compiler error:
>> "c:\components\in-process\connectablecomponent\stdafx.cpp(5) : error
>> C2850: 'PCH header file' : only allowed at file scope; may not be in a
>> nested construct"
>>
>> It points to stdafx.cpp.
>> How to solve this ?
>>
>> thank you
>> Vilius
>
> Do you understand the way the precompiled header feature works? Check
> your stdafx.cpp file. Nothing except comments may preceed the
>
> #include "stdafx.h"
>
> --
> Scott McPhillips [VC++ MVP]
>



Re: Annoying compiler error ? by Vilius

Vilius
Tue Oct 24 17:51:14 CDT 2006

never mind - solved

"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:%235dD%23V79GHA.1168@TK2MSFTNGP03.phx.gbl...
> Vilius wrote:
>> Hi guys,
>>
>> I have compiler error:
>> "c:\components\in-process\connectablecomponent\stdafx.cpp(5) : error
>> C2850: 'PCH header file' : only allowed at file scope; may not be in a
>> nested construct"
>>
>> It points to stdafx.cpp.
>> How to solve this ?
>>
>> thank you
>> Vilius
>
> Do you understand the way the precompiled header feature works? Check
> your stdafx.cpp file. Nothing except comments may preceed the
>
> #include "stdafx.h"
>
> --
> Scott McPhillips [VC++ MVP]
>



Re: Annoying compiler error ? by bruno_nos_pam_van_dooren

bruno_nos_pam_van_dooren
Wed Oct 25 01:48:02 CDT 2006

> never mind - solved

If you post the above line, please include the solution as well.
That way we all learn something.

--
Kind regards,
Bruno.
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"

Re: Annoying compiler error ? by Vilius

Vilius
Wed Oct 25 08:37:04 CDT 2006

I forgot semicolon after last class definition in class header file -
it's really unusual to get that kind of error because of that.


"Bruno van Dooren [MVP VC++]" <bruno_nos_pam_van_dooren@hotmail.com> wrote
in message news:6F2E2D00-E73A-4DE8-9033-3508BD9E3ABB@microsoft.com...
>> never mind - solved
>
> If you post the above line, please include the solution as well.
> That way we all learn something.
>
> --
> Kind regards,
> Bruno.
> bruno_nos_pam_van_dooren@hotmail.com
> Remove only "_nos_pam"



Re: Annoying compiler error ? by Bruno

Bruno
Wed Oct 25 14:31:57 CDT 2006

>I forgot semicolon after last class definition in class header file -
> it's really unusual to get that kind of error because of that.

Ah :-)

As any C++ veteran will tell you:
If you have an error that doesn't make any sense whatsoever, chances are
that you either forgot a semicolon or a curly brace in the lines (or header
file) immediatly preceding the error.

I have seen the weirdest error message because of a missing semicolon.

--

Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"



Re: Annoying compiler error ? by Ben

Ben
Thu Oct 26 08:52:48 CDT 2006

"Vilius" <v_mockunas@delfi.lt.removespam> wrote in message
news:%23HBRqqD%23GHA.1172@TK2MSFTNGP03.phx.gbl...
>I forgot semicolon after last class definition in class header file -
> it's really unusual to get that kind of error because of that.
>

Without semicolon, the compiler is ready to declare a variable, which would
not be considered the "file scope" state. So it generates an error pointing
to the PCH, which is probably better than the alternative which would be a
syntax error in every .cpp file on the first line following the #include
"stdafx.h"

>
> "Bruno van Dooren [MVP VC++]" <bruno_nos_pam_van_dooren@hotmail.com> wrote
> in message news:6F2E2D00-E73A-4DE8-9033-3508BD9E3ABB@microsoft.com...
>>> never mind - solved
>>
>> If you post the above line, please include the solution as well.
>> That way we all learn something.
>>
>> --
>> Kind regards,
>> Bruno.
>> bruno_nos_pam_van_dooren@hotmail.com
>> Remove only "_nos_pam"
>
>