473,405 Members | 2,279 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,405 software developers and data experts.

headers - best practice?

suppose you have a .cpp file that needs things from headers A and B,
and it is known that header A already includes B. should I still put
include B in .cpp just in case I will move some code related to B only
some day? or should I keep those countless #includes to the minimum?
what are other pros/cons?

Jul 12 '07 #1
4 1495
On Jul 12, 3:04 pm, makc <makc.the.gr...@gmail.comwrote:
suppose you have a .cpp file that needs things from headers A and B,
and it is known that header A already includes B. should I still put
include B in .cpp just in case I will move some code related to B only
some day? or should I keep those countless #includes to the minimum?
what are other pros/cons?
can you clarify what you want but i think that you need to include
the header b once in the .cpp so you can put this code in b to
or any other file to be ensure that that header will included
once

#ifndef _B_
#define _B_

(put your header content here)

#end if

Jul 12 '07 #2
Virtual_X wrote:
On Jul 12, 3:04 pm, makc <makc.the.gr...@gmail.comwrote:
>suppose you have a .cpp file that needs things from headers A and B,
and it is known that header A already includes B. should I still put
include B in .cpp just in case I will move some code related to B
only some day? or should I keep those countless #includes to the
minimum? what are other pros/cons?

can you clarify what you want but i think that you need to include
the header b once in the .cpp so you can put this code in b to
or any other file to be ensure that that header will included
once

#ifndef _B_
#define _B_
Identifiers that begin with an underscore and a capital letter are
reserved by the implementation.
>
(put your header content here)

#end if
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 12 '07 #3
On Jul 13, 12:04 am, makc <makc.the.gr...@gmail.comwrote:
suppose you have a .cpp file that needs things from headers A and B,
and it is known that header A already includes B. should I still put
include B in .cpp just in case I will move some code related to B only
some day? or should I keep those countless #includes to the minimum?
what are other pros/cons?
Anything you use directly, include the header file for it.
Anything which is only used indirectly, don't.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 13 '07 #4
"makc" <ma************@gmail.comwrote in message
news:11*********************@g4g2000hsf.googlegrou ps.com...
suppose you have a .cpp file that needs things from headers A and B,
and it is known that header A already includes B. should I still put
include B in .cpp just in case I will move some code related to B only
some day? or should I keep those countless #includes to the minimum?
what are other pros/cons?
Personally, I use header guards, and would include both A.h and B.h in my
..cpp file if I am creating a type B. It just makes it easier for
maintanance when sometime in the future I see
class B
and wonder where class B is definred. I see
#incluce "B.h"
at the top of my source, no problem, I open the file and go on my way.
Without "B.h" being defined I would have to spend extra time figuring out
what header actually included class B.
Jul 13 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

71
by: Christopher Benson-Manica | last post by:
At what point was the .h dropped from the STL headers? I just had a discussion yesterday with my boss, who said he wanted .h on all the STL includes, despite me protesting that it was not...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
4
by: Ned Balzer | last post by:
Hi all, I am pretty new to asp.net; I've done lots of classic asp, but am just beginning to get my mind wrapped around .net. What I'd like to do is include some code that tests if a user is...
4
by: Rui.Hu719 | last post by:
Hi, All: I read the following passage from a book: "There are three exceptions to the rule that headers should not contain definitions: classes, const objects whose value is known at compile...
22
by: Platero | last post by:
Hi, I've a stupid question but... The code is the following: if(($role!='tutor')&&(array_key_exists('tutor_id',$_GET))) { $possible_ids = array(2,6,7,8,9,10); $t_id = $_GET;
9
by: =?Utf-8?B?QW1tZXI=?= | last post by:
I've read many incomplete opinions about the "Best Practice" for securely accessing SQL but what I really need to find the "Best Practice" that fits my applications needs. Currently (alpha...
14
by: broli | last post by:
In my project it is getting really messy to take care of all the headers..for eg. right now I have following modules in my project - vector.c vector.h test.c reader.h reader.c vector.h
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.