Solved

How do i properly use Header and implementation files?

Posted on 2008-10-01
9
302 Views
Last Modified: 2010-04-24
General question for Visual C++. How do i include header files and other .cpp files (implementation files) in my program so that i dont have to keep it all in one file? what is the syntax, an example would be choosen as the solution right away. Thanks.
/*this is the stdafx.h header file that comes when you start a CLR console app in VC++ and how im trying to include another header file in my project*/
 
#pragma once
#include "header.h"

Open in new window

0
Comment
Question by:vaavoom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 22621352
not sure about your question, but this is the standard practice:

you put class declarations and other global variables and definitions at .h files
you put class implementations at .cpp files

all files are included in your project
in every cpp file, put put an #include directive to reference the .h file related with the classes you will use at the current implementation file.

0
 

Author Comment

by:vaavoom
ID: 22621434
ok that helped actually but one thing im not clear on is:

in the header file i get errors that strings are not declared. The #include <string> does not seem to work in header files. Am i stuck using std::string?? Thanks
0
 

Author Closing Comment

by:vaavoom
ID: 31502258
i tinkered around to solve it myself, thanks tho.
0
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22621474
if you want more clarifications, ask Community Support to reopen the question and let me the chance to have a grade better than C.
0
 

Author Comment

by:vaavoom
ID: 22621497
Done.
when it comes back ill give you an A. Sorry im fresh and new here at EE but go ahead and give me and answer and also i was wondering:

does getting a bad grade affect some sort of track record you have? i dont mean to insult with it just trying to be fair.

Thanks again.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22621554
it does not affect my score, since I have a very high one, but it means "your answer was barely correct and/or poor of details, although you had the opportunity to do it better"

about the string header, it should work, but you will need to put in your code:

using namespace std;

usually it is done after the #include directives. Do you have it yet?
0
 

Author Comment

by:vaavoom
ID: 22621560
i do that makes sense... im now trying to figure out how to alter the grade given lol.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22621610
you have to ask to reopen the question, I will do this for you....
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question