View Single Post
  #13   Spotlight this post!  
Unread 06-05-2004, 12:46
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Re: Error in Visual C++

Alright, here's a quick run-down of PCH (pre-compiled headers):

In REALLY big projects, there are sometimes files that need to be included in every other file (like externs for global variables, a few function prototypes, maybe even a few classes).

Normally, #include works like copy-paste in C++ files (ie, the #included file is literally inserted in place of the #include). This is done by the preprocessor, so the compiler doesn't even know that there used to be a #include.

In large projects, this means that the #included file will have to be re-compiled as part of each file in which it was included. This can be a HUGE time-waster since it will compile to the same thing every single time.

With PCHs, the development environment essentially keeps track of these files specially, compiles them once, and then essentially copy-pastes the compiled code into each file instead of the raw source. Thus, the compiler only needs to compile it once, and much time could be saved.



Now, on to your problem:
1. PCHs are almost useless in small projects. Avoid them unless you actually need them.

2. VC++ disagrees with me. Whenever it creates a new project, it automatically assumes you want PCHs.

3. VC++ doesn't like being told it's wrong. If it can't find the #include of the PCH, it will complain.

There are two solutions to the problem:

1. Turn off precompiled headers in your project. I don't have a copy of .NET, but in VC++ 6.0, you do this by going to Project -> Settings -> C/C++ tab, choose "Precompiled Headers" from the category drop-down box, and select "Not using precompiled headers".

2. Give in to VC++ and simply add a #include "stdafx.h" to the top of every file. (stdafx.h is the name VC++ gives to the PCH).


While we're on the topic, if you're just learning C++, you should always tell VC++ to create a "Win32 console application" and make it of the "Hello, World!" type. Then, just delete the main function they give you and replace it with your own.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php