SlideShare a Scribd company logo
COMP 2710 Software Construction
Header Files
Dr. Xiao Qin
Auburn University
http://www.eng.auburn.edu/~xqin
xqin@auburn.edu
C++ Header Files
• Build libraries of classes or functions
• Re-used by many different programs
• Just like predefined libraries
1-2
Build Libraries of Classes or
Functions
1-3
Header File Inclusion Rules
• The inclusion mechanism should be tolerant to
duplicate header file inclusions.
• A header file should be included only when a
forward declaration would not do the job.
• The order of header file inclusion is not
important.
1-4
Rule 1: Be tolerant to duplicate
header file inclusions.
/*
* Header file name: estimate_function.h
*/
#ifndef ESTIMATE_FUNCTION_H
#define ESTIMATE_FUNCTION_H
#include <iostream>
using namespace std;
double estimateOfTotal(int minPeas, int maxPeas,
int podCount);
#endif
1-5
Rule 2: Use forward declaration
when possible.
Suppose we want to define a new class B that uses objects
of class A.
class B {
private:
A* fPtrA ;
public:
void myMethod(const& A) const ;
};
1-6
#include <A.h>;
B only uses references or pointers to A. Use forward
declaration then: you don't need to include <A.h>. This
will in turn speed a little bit the compilation.
class A;
When we need to include <A.h>?
• B derives from A or B explicitely (or implicitely) uses
objects of class A. You then need to include <A.h>
class B : public A {
} ;
class C {
private:
A fA ;
public:
void myMethod(A par) ;
};
1-7
#include <A.h>;
Exercise 1: Header Files
• Assume a class A with code stored in a.cpp and a.h.
#ifndef A_H
#define A_H
#include "abase.h"
#include "b.h"
// Forward Declarations/definition
class C;
class D;
class A : public ABase {
B m_b;
C *m_c;
D *m_d;
public:
void SetC(C *c);
C * GetC() const;
void ModifyD(D *d);
};
#endif 1-8

More Related Content

Viewers also liked

Energy Efficient Data Storage Systems
Energy Efficient Data Storage SystemsEnergy Efficient Data Storage Systems
Energy Efficient Data Storage Systems
Xiao Qin
 
Thermal modeling and management of cluster storage systems xunfei jiang 2014
Thermal modeling and management of cluster storage systems xunfei jiang 2014Thermal modeling and management of cluster storage systems xunfei jiang 2014
Thermal modeling and management of cluster storage systems xunfei jiang 2014
Xiao Qin
 
Common grammar mistakes
Common grammar mistakesCommon grammar mistakes
Common grammar mistakesXiao Qin
 
Why Major in Computer Science and Software Engineering at Auburn University?
Why Major in Computer Science and Software Engineering at Auburn University?Why Major in Computer Science and Software Engineering at Auburn University?
Why Major in Computer Science and Software Engineering at Auburn University?
Xiao Qin
 
Surviving a group project
Surviving a group projectSurviving a group project
Surviving a group project
Xiao Qin
 
Project 2 how to install and compile os161
Project 2 how to install and compile os161Project 2 how to install and compile os161
Project 2 how to install and compile os161
Xiao Qin
 
Project 2 How to modify os161: A Manual
Project 2 How to modify os161: A ManualProject 2 How to modify os161: A Manual
Project 2 How to modify os161: A Manual
Xiao Qin
 
How to add system calls to OS/161
How to add system calls to OS/161How to add system calls to OS/161
How to add system calls to OS/161
Xiao Qin
 
COMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercisesCOMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercises
Xiao Qin
 
Data center specific thermal and energy saving techniques
Data center specific thermal and energy saving techniquesData center specific thermal and energy saving techniques
Data center specific thermal and energy saving techniques
Xiao Qin
 
Understanding what our customer wants-slideshare
Understanding what our customer wants-slideshareUnderstanding what our customer wants-slideshare
Understanding what our customer wants-slideshare
Xiao Qin
 
Performance Evaluation of Traditional Caching Policies on a Large System with...
Performance Evaluation of Traditional Caching Policies on a Large System with...Performance Evaluation of Traditional Caching Policies on a Large System with...
Performance Evaluation of Traditional Caching Policies on a Large System with...
Xiao Qin
 
HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...
HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...
HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...
Xiao Qin
 

Viewers also liked (13)

Energy Efficient Data Storage Systems
Energy Efficient Data Storage SystemsEnergy Efficient Data Storage Systems
Energy Efficient Data Storage Systems
 
Thermal modeling and management of cluster storage systems xunfei jiang 2014
Thermal modeling and management of cluster storage systems xunfei jiang 2014Thermal modeling and management of cluster storage systems xunfei jiang 2014
Thermal modeling and management of cluster storage systems xunfei jiang 2014
 
Common grammar mistakes
Common grammar mistakesCommon grammar mistakes
Common grammar mistakes
 
Why Major in Computer Science and Software Engineering at Auburn University?
Why Major in Computer Science and Software Engineering at Auburn University?Why Major in Computer Science and Software Engineering at Auburn University?
Why Major in Computer Science and Software Engineering at Auburn University?
 
Surviving a group project
Surviving a group projectSurviving a group project
Surviving a group project
 
Project 2 how to install and compile os161
Project 2 how to install and compile os161Project 2 how to install and compile os161
Project 2 how to install and compile os161
 
Project 2 How to modify os161: A Manual
Project 2 How to modify os161: A ManualProject 2 How to modify os161: A Manual
Project 2 How to modify os161: A Manual
 
How to add system calls to OS/161
How to add system calls to OS/161How to add system calls to OS/161
How to add system calls to OS/161
 
COMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercisesCOMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercises
 
Data center specific thermal and energy saving techniques
Data center specific thermal and energy saving techniquesData center specific thermal and energy saving techniques
Data center specific thermal and energy saving techniques
 
Understanding what our customer wants-slideshare
Understanding what our customer wants-slideshareUnderstanding what our customer wants-slideshare
Understanding what our customer wants-slideshare
 
Performance Evaluation of Traditional Caching Policies on a Large System with...
Performance Evaluation of Traditional Caching Policies on a Large System with...Performance Evaluation of Traditional Caching Policies on a Large System with...
Performance Evaluation of Traditional Caching Policies on a Large System with...
 
HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...
HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...
HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...
 

Similar to COMP2710 Software Construction: header files

Lecture 8_Libraries.pptx
Lecture 8_Libraries.pptxLecture 8_Libraries.pptx
Lecture 8_Libraries.pptx
NelyJay
 
C- language Lecture 8
C- language Lecture 8C- language Lecture 8
C- language Lecture 8
Hatem Abd El-Salam
 
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docxi Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
cwayne3
 
Asp .net folders and web.config
Asp .net folders and web.configAsp .net folders and web.config
Asp .net folders and web.config
baabtra.com - No. 1 supplier of quality freshers
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
Deepak Chandani
 
Asp .net folders and web.config
Asp .net folders and web.configAsp .net folders and web.config
Asp .net folders and web.config
baabtra.com - No. 1 supplier of quality freshers
 
Python Course In Chandigarh
Python Course In ChandigarhPython Course In Chandigarh
Python Course In Chandigarh
Excellence Academy
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part I
DUSPviz
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
VishuSaini22
 
An Introduction To Python - Modules & Solving Real World Problems
An Introduction To Python - Modules & Solving Real World ProblemsAn Introduction To Python - Modules & Solving Real World Problems
An Introduction To Python - Modules & Solving Real World Problems
Blue Elephant Consulting
 
Crosslingual search-engine
Crosslingual search-engineCrosslingual search-engine
Crosslingual search-engine
Carlos Badenes-Olmedo
 
Uop pos 433 week 3 linux
Uop pos 433 week 3 linuxUop pos 433 week 3 linux
Uop pos 433 week 3 linux
shyaminfopvtltd
 
Uop pos 433 week 3 linux
Uop pos 433 week 3 linuxUop pos 433 week 3 linux
Uop pos 433 week 3 linux
anjuchandu755
 
Uop pos 433 week 3 linux
Uop pos 433 week 3 linuxUop pos 433 week 3 linux
Uop pos 433 week 3 linux
ElijahEthaan
 
Effective Objective-C 2.0 (Item 1 - 7)
Effective Objective-C 2.0 (Item 1 - 7)Effective Objective-C 2.0 (Item 1 - 7)
Effective Objective-C 2.0 (Item 1 - 7)
Sean Tsai
 
Autoconf&Automake
Autoconf&AutomakeAutoconf&Automake
Autoconf&Automake
niurui
 

Similar to COMP2710 Software Construction: header files (20)

Workshop1
Workshop1Workshop1
Workshop1
 
Lecture 8_Libraries.pptx
Lecture 8_Libraries.pptxLecture 8_Libraries.pptx
Lecture 8_Libraries.pptx
 
C- language Lecture 8
C- language Lecture 8C- language Lecture 8
C- language Lecture 8
 
LXC NSAttach
LXC NSAttachLXC NSAttach
LXC NSAttach
 
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docxi Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
 
Asp .net folders and web.config
Asp .net folders and web.configAsp .net folders and web.config
Asp .net folders and web.config
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
 
Chtp415
Chtp415Chtp415
Chtp415
 
Asp .net folders and web.config
Asp .net folders and web.configAsp .net folders and web.config
Asp .net folders and web.config
 
Python Course In Chandigarh
Python Course In ChandigarhPython Course In Chandigarh
Python Course In Chandigarh
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part I
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
An Introduction To Python - Modules & Solving Real World Problems
An Introduction To Python - Modules & Solving Real World ProblemsAn Introduction To Python - Modules & Solving Real World Problems
An Introduction To Python - Modules & Solving Real World Problems
 
Crosslingual search-engine
Crosslingual search-engineCrosslingual search-engine
Crosslingual search-engine
 
CodeIgniter & MVC
CodeIgniter & MVCCodeIgniter & MVC
CodeIgniter & MVC
 
Uop pos 433 week 3 linux
Uop pos 433 week 3 linuxUop pos 433 week 3 linux
Uop pos 433 week 3 linux
 
Uop pos 433 week 3 linux
Uop pos 433 week 3 linuxUop pos 433 week 3 linux
Uop pos 433 week 3 linux
 
Uop pos 433 week 3 linux
Uop pos 433 week 3 linuxUop pos 433 week 3 linux
Uop pos 433 week 3 linux
 
Effective Objective-C 2.0 (Item 1 - 7)
Effective Objective-C 2.0 (Item 1 - 7)Effective Objective-C 2.0 (Item 1 - 7)
Effective Objective-C 2.0 (Item 1 - 7)
 
Autoconf&Automake
Autoconf&AutomakeAutoconf&Automake
Autoconf&Automake
 

More from Xiao Qin

How to apply for internship positions?
How to apply for internship positions?How to apply for internship positions?
How to apply for internship positions?
Xiao Qin
 
How to write research papers? Version 5.0
How to write research papers? Version 5.0How to write research papers? Version 5.0
How to write research papers? Version 5.0
Xiao Qin
 
Making a competitive nsf career proposal: Part 2 Worksheet
Making a competitive nsf career proposal: Part 2 WorksheetMaking a competitive nsf career proposal: Part 2 Worksheet
Making a competitive nsf career proposal: Part 2 Worksheet
Xiao Qin
 
Making a competitive nsf career proposal: Part 1 Tips
Making a competitive nsf career proposal: Part 1 TipsMaking a competitive nsf career proposal: Part 1 Tips
Making a competitive nsf career proposal: Part 1 Tips
Xiao Qin
 
Auburn csse faculty orientation
Auburn csse faculty orientationAuburn csse faculty orientation
Auburn csse faculty orientation
Xiao Qin
 
Auburn CSSE graduate student orientation
Auburn CSSE graduate student orientationAuburn CSSE graduate student orientation
Auburn CSSE graduate student orientation
Xiao Qin
 
CSSE Graduate Programs Committee: Progress Report
CSSE Graduate Programs Committee: Progress ReportCSSE Graduate Programs Committee: Progress Report
CSSE Graduate Programs Committee: Progress Report
Xiao Qin
 
P#1 stream of praise
P#1 stream of praiseP#1 stream of praise
P#1 stream of praise
Xiao Qin
 
Reliability Modeling and Analysis of Energy-Efficient Storage Systems
Reliability Modeling and Analysis of Energy-Efficient Storage SystemsReliability Modeling and Analysis of Energy-Efficient Storage Systems
Reliability Modeling and Analysis of Energy-Efficient Storage Systems
Xiao Qin
 

More from Xiao Qin (9)

How to apply for internship positions?
How to apply for internship positions?How to apply for internship positions?
How to apply for internship positions?
 
How to write research papers? Version 5.0
How to write research papers? Version 5.0How to write research papers? Version 5.0
How to write research papers? Version 5.0
 
Making a competitive nsf career proposal: Part 2 Worksheet
Making a competitive nsf career proposal: Part 2 WorksheetMaking a competitive nsf career proposal: Part 2 Worksheet
Making a competitive nsf career proposal: Part 2 Worksheet
 
Making a competitive nsf career proposal: Part 1 Tips
Making a competitive nsf career proposal: Part 1 TipsMaking a competitive nsf career proposal: Part 1 Tips
Making a competitive nsf career proposal: Part 1 Tips
 
Auburn csse faculty orientation
Auburn csse faculty orientationAuburn csse faculty orientation
Auburn csse faculty orientation
 
Auburn CSSE graduate student orientation
Auburn CSSE graduate student orientationAuburn CSSE graduate student orientation
Auburn CSSE graduate student orientation
 
CSSE Graduate Programs Committee: Progress Report
CSSE Graduate Programs Committee: Progress ReportCSSE Graduate Programs Committee: Progress Report
CSSE Graduate Programs Committee: Progress Report
 
P#1 stream of praise
P#1 stream of praiseP#1 stream of praise
P#1 stream of praise
 
Reliability Modeling and Analysis of Energy-Efficient Storage Systems
Reliability Modeling and Analysis of Energy-Efficient Storage SystemsReliability Modeling and Analysis of Energy-Efficient Storage Systems
Reliability Modeling and Analysis of Energy-Efficient Storage Systems
 

Recently uploaded

MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
NelTorrente
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 

COMP2710 Software Construction: header files

  • 1. COMP 2710 Software Construction Header Files Dr. Xiao Qin Auburn University http://www.eng.auburn.edu/~xqin xqin@auburn.edu
  • 2. C++ Header Files • Build libraries of classes or functions • Re-used by many different programs • Just like predefined libraries 1-2
  • 3. Build Libraries of Classes or Functions 1-3
  • 4. Header File Inclusion Rules • The inclusion mechanism should be tolerant to duplicate header file inclusions. • A header file should be included only when a forward declaration would not do the job. • The order of header file inclusion is not important. 1-4
  • 5. Rule 1: Be tolerant to duplicate header file inclusions. /* * Header file name: estimate_function.h */ #ifndef ESTIMATE_FUNCTION_H #define ESTIMATE_FUNCTION_H #include <iostream> using namespace std; double estimateOfTotal(int minPeas, int maxPeas, int podCount); #endif 1-5
  • 6. Rule 2: Use forward declaration when possible. Suppose we want to define a new class B that uses objects of class A. class B { private: A* fPtrA ; public: void myMethod(const& A) const ; }; 1-6 #include <A.h>; B only uses references or pointers to A. Use forward declaration then: you don't need to include <A.h>. This will in turn speed a little bit the compilation. class A;
  • 7. When we need to include <A.h>? • B derives from A or B explicitely (or implicitely) uses objects of class A. You then need to include <A.h> class B : public A { } ; class C { private: A fA ; public: void myMethod(A par) ; }; 1-7 #include <A.h>;
  • 8. Exercise 1: Header Files • Assume a class A with code stored in a.cpp and a.h. #ifndef A_H #define A_H #include "abase.h" #include "b.h" // Forward Declarations/definition class C; class D; class A : public ABase { B m_b; C *m_c; D *m_d; public: void SetC(C *c); C * GetC() const; void ModifyD(D *d); }; #endif 1-8

Editor's Notes

  1. Reference: http://stackoverflow.com/questions/4757565/c-forward-declaration How forward-declarations can significantly reduce build times You can get the declaration of a function into your current .cpp or .h file by #includ&amp;apos;ing the header that already contains a declaration of the function. However, this can slow down your compile, especially if you #include a header into a .h instead of .cpp of your program, as everything that #includes the .h you&amp;apos;re writing would end up #include&amp;apos;ing all the headers you wrote #includes for too. Suddenly the compiler has #included pages and pages of code that it needs to compile even when you only wanted to use one or two functions. To avoid this, you can use a forward-declaration and just type the declaration of the function yourself at the top of the file. If you&amp;apos;re only using a few functions, this can really make your compiles quicker compared to always #including the header. For really large project the difference could be an hour or more of compile time bought down to a few minutes.
  2. Reference: http://stackoverflow.com/questions/4757565/c-forward-declaration How forward-declarations can significantly reduce build times You can get the declaration of a function into your current .cpp or .h file by #includ&amp;apos;ing the header that already contains a declaration of the function. However, this can slow down your compile, especially if you #include a header into a .h instead of .cpp of your program, as everything that #includes the .h you&amp;apos;re writing would end up #include&amp;apos;ing all the headers you wrote #includes for too. Suddenly the compiler has #included pages and pages of code that it needs to compile even when you only wanted to use one or two functions. To avoid this, you can use a forward-declaration and just type the declaration of the function yourself at the top of the file. If you&amp;apos;re only using a few functions, this can really make your compiles quicker compared to always #including the header. For really large project the difference could be an hour or more of compile time bought down to a few minutes.
  3. Reference: http://stackoverflow.com/questions/4757565/c-forward-declaration How forward-declarations can significantly reduce build times You can get the declaration of a function into your current .cpp or .h file by #includ&amp;apos;ing the header that already contains a declaration of the function. However, this can slow down your compile, especially if you #include a header into a .h instead of .cpp of your program, as everything that #includes the .h you&amp;apos;re writing would end up #include&amp;apos;ing all the headers you wrote #includes for too. Suddenly the compiler has #included pages and pages of code that it needs to compile even when you only wanted to use one or two functions. To avoid this, you can use a forward-declaration and just type the declaration of the function yourself at the top of the file. If you&amp;apos;re only using a few functions, this can really make your compiles quicker compared to always #including the header. For really large project the difference could be an hour or more of compile time bought down to a few minutes.