473,382 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to manage C++ Header and source files?

Hi,
I am working on a c++ project. I want to define my own classes. I define each class in a separate header file, and define the body of its methods in another source cpp file. For example:
/
Expand|Select|Wrap|Line Numbers
  1. //Person.h
  2. class Person
  3. {
  4. // data members and methods.
  5. };
  6.  
  7. //Person.cpp
  8. #include "Person.h"
  9. //define the body of the methods here.
The problem that I face now, is that I have many classes (more than 50). That's why I decided to split classes among folders (like packages in java).
I put all header files in a structure like this:

-include
-humans
-employees
-students



and created another structure for source cpp files like this:
-humans
-employees
-students

The problem is that I have to provide the relative path of the file I want to include. For example, if I want to include Pupil.h in the source file Pupil.cpp :
Expand|Select|Wrap|Line Numbers
  1. #include "../../include/humans/students.Pupil.h";
which looks ugly!

I guess using namespaces could help, right ?
Any ideas?

Thanks,
Jul 17 '07 #1
2 3170
Darryl
86
You could add the paths to list of paths your compiler searches when looking for headers.
Jul 17 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
problem is that I have to provide the relative path of the file I want to include. For example, if I want to include Pupil.h in the source file Pupil.cpp :

Code: ( text )
#include "../../include/humans/students.Pupil.h";
What Darryl means is that you should change your code to:

#include <Pupil.h>

and add the path to Pupil.h as a standard search path for the preprocessor.

If you use Visual C++, go to the Project Properties, select c/C++, select Preprocsssor and add the path to Pupil .h. If you have many paths, seprate the paths by semi-colons.

As a variation you can:

#include "Pupil.h"

which causes the proprocessor to firts look in your project folder. If the file is not there, the search reverts back to #include <Pupil.h>.

Avoid relative paths in your code. Big no-no.
Jul 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: OpSoftware | last post by:
Program to manage .ASP Include-Files... on: http://members.chello.at/otmar.pilgerstorfer/ enjoy it, and give me feedback, o.p.
2
by: Sean Dettrick | last post by:
I am wondering if it is possible to increment an integer at compile time using template<int N> (or by any other method, e.g. compiler directives etc), across multiple source files. This may...
7
by: Olivier Mandavy | last post by:
Hello, i'm looking for guidelines about what are the comments to be written at the beginning of source files. Thanks a lot. Olivier
4
by: rajkirangrandhi | last post by:
Hi, I have several classes written in Java that I am trying to convert into C++. They are fairly simple classes, no gui stuff etc, just some math routines. I was able to do it without any problem....
3
by: G Patel | last post by:
Hello, If a program has two source files: main.c secondaryfunctions.c and I have a header file: secondaryfunctions.h (with prototypes for the function) The only function in main.c is main()...
17
by: Leif | last post by:
Hello All, Last week (11 Nov 05) with the Subject header: "XHTML 1.0 Strict validation problem", I tried to describe a validation problem with text added to my source files in XHTML. I was...
2
by: jeremy.figgins | last post by:
Hi, I have a class that is fairly large and I would like to split the file into two files, but still use only one class. What is the best way to accomplish this? Thanks!
5
by: Egbert Nierop \(MVP for IIS\) | last post by:
hi, I have a testing win2003 machine, where I debug inside a MMC process using a DebugBreak() statement. But only the first time, source code was shown, after that, I only get to see...
2
by: mcdesigns | last post by:
Recently suffered a bad hard drive crash. Was able to recover most of my old source files, but most were corrupted. Does anyone know if Visual Studio does any caching of source files? Have tried...
6
by: Oliver Graeser | last post by:
Ok, stupid question.... I used to write programs all into one text files and compile them. Works, fine. Then I discovered XCode (or IDEs in general) which appear to be really increasing my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.