• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# What is wrong with c++???

## Recommended Posts

ageny6    122
Okay, here is the deal. My program was working fine the night before. But right about 10 minutes ago, I changed functions from _putch to cout<< in about 3 lines of code and included the library concequently. No biggy, right? Well, when I compiled, I got a real suprize. My compiler is giving me a insteresting new error that I have never even heard about. For example, the set of code before the main: #include "apstring.h" int GetPlayerOption(); gives this error: error C2143: syntax error : missing '';'' before ''PCH creation point'' pointing at the function decleration line int GetPlayerOption();... And then this error is repeated for every single line of code in my driver.cpp file (the file with the code above). What in the world is this error??? Jonathan

##### Share on other sites
Rob Loach    1504
Check out "apstring.h". It might be in there.

Rob Loach
Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore

"Do or do not. There is no try."
- Yoda

##### Share on other sites
Guest Anonymous Poster
Are you using Visual Studio? Delete all the files except for your .dsw, .dsp, and of course your source code. Be sure to delete the Debug and Release folders. This will force Studio to rebuild all those files and redo the precompiled headers. That often fixes this problem for me. If your not using Studio, then, umm, next?

##### Share on other sites
Willm    138
Do you have a carriage return after the inclusion guard in "apstring.h"?

##### Share on other sites
Rob Loach    1504
Also, try using:
#include <apstring.h>

I doubt it''ll help, but might as well try.

Rob Loach
Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore

"Do or do not. There is no try."
- Yoda

##### Share on other sites
antareus    576
The AP is closest.

Its complaining because it can''t find the header it wants for precompiled headers, typically this is named something like StdAfx.h in your project. Check your project settings and look for an option relating to precompiled headers--try turning it off.

##### Share on other sites
Guest Anonymous Poster
thats not the problem at all. at the very top of your program, add #include "stdafx.h" before everything else. tat will fix it.

##### Share on other sites
cowsarenotevil    3005
quote:
Original post by Anonymous Poster
thats not the problem at all. at the very top of your program, add #include "stdafx.h" before everything else. tat will fix it.

Actually, that''s only a fix because of the PCH.

-~-The Cow of Darkness-~-

If you see the image I am online

##### Share on other sites
i''ve had this happen. What I did was put all my #include statements into the file stdafx.h and #include stdafx.h in all the files instead of #including you''re files directly. I know, it''s a pain, hope that helps!

##### Share on other sites
Oluseyi    2103
Listen to antareus. He''s the only one who completely understands what he''s saying. Oh, and learn your IDE. It often has requirements that extend beyond the language (like PCHs).

##### Share on other sites
antareus    576
This thread is annoyingly ironic because I used to know how to set up PCH properly, but now I don''t. I find the requirement that the PCH header must be at the top of every source file rather asinine.

##### Share on other sites
"apstring" sounds an awfully lot like Advanced Placement string for AP Computer Science A or AB in High School right? I took that class now 4 years ago, and we used metrowerks codewarrior, not VC++. Besides VC++ gives a different error message for PCH file errors.

I don''t know how to configure codewarrior, or how PCH''s work in it, but i do for VC++. Here''s my view on how they work in VC++ 6.0:

You have a common header file like "stdafx.h" with its associated "stdafx.cpp" file. Now stdafx.cpp has only 1 compile line: #include "stdafx.h". Why the seeming uselessness of this cpp file? It''s in your project settings.

In vc++ 6.0, right click on the cpp file (stdafx.cpp in this case) and goto settings. Under the C/C++ tab, there''s a pulldown box labeled categories. Put that to Precompiled Headers. Notice this: stdafx.cpp is set to create precompiled header file through file: stdafx.h. Any other files in your project will be set to: use precompiled header file though header: stdafx.h. That''s the importance of stdafx.cpp: It is always the first cpp file to be compiled because it is the file which creates the PCH file in the first place so the other cpp files can use it.

Now, it is also from this settings menu that you can turn off the use of PCH files for certain cpp files. You simply select the cpp file you want and select the option: not using precompiled headers. This way you don''t have to include the pch header at the top of every source file. This is vital when you have different projects that share common cpp and header files that cannot be modified.

I must say PCH files are awesome. My compile times on my game are down from 2 minutes to less than 15 seconds using them.

##### Share on other sites
Willm    138
The error is misleading and generally has nothing to do with PCHs. Its far more likely to be a parenthesis snafu in one of the earlier headers.

##### Share on other sites
ageny6    122
quote:
Original post by Willm
The error is misleading and generally has nothing to do with PCHs. Its far more likely to be a parenthesis snafu in one of the earlier headers.

The example I gave was the very first header in the driver program!!! That cannot be it.

Jonathan

##### Share on other sites
sjelkjd    171
quote:
Original post by Willm
The error is misleading and generally has nothing to do with PCHs. Its far more likely to be a parenthesis snafu in one of the earlier headers.

This post is misleading and generally has nothing to do with your problem. It is far more likely to be explained in another post regarding PCHs.

##### Share on other sites
billybob    134
i get that error on every function if i forget a semicolon on the last line of a header (usually the one after the } for a class)

##### Share on other sites
ageny6    122
quote:
"apstring" sounds an awfully lot like Advanced Placement string for AP Computer Science A or AB in High School right?

BTW, you are right!

As for the semicolon after the } in the class, it is there, so it could not be the problem

Jonathan

[edited by - ageny6 on May 27, 2003 8:16:49 PM]