SlideShare a Scribd company logo
1 of 7
Multiple-FilePrograms,
Inheritance,Templates
•Multiple-File Programs
• header files
• implementation files
• main-program file)
1
2
Why MultipleFiles
• Re-use
• Better data abstraction (datahiding)
• More manageability of largeprograms
3
The Multiple-FileApproach
• Haveeach major classasaseparate program
• Re-use:Theclasscanthen be used by other programs using the #include
macro instead of the copy-&-pasteapproach
• Put the class/function declarations in a header (.h) file, and the
class/function implementations in another (.c or .cpp) file. This
achieves data hiding.
4
Example
class Stack{
public:
typedef int dtype;
Stack(int cap=100);
int getCapacity();
void push(dtypeb);
dtype pop();
dtype peek();
bool isEmpty();
private:
dtype *dataptr;
int top;
int capacity;
};
#include"Stack.h"
Stack::Stack(intcap){
top=0;
capacity =(cap>0)?cap:100;
dataptr =newint[capacity];
};
int Stack::getCapacity( ) {
return capacity;
};
int Stack::dtype Stack::pop(){
assert(!isEmpty());
returndataptr[--top];
};
// the implementation of
// the remaining methods
........
#include <cstdlib>
#include<iostream>
#include"Stack.h”
using namespacestd;
// local stuff,ifany
int main(intargc,
char*argv[]){
………
}
Stack.hfile: Stack.cpp file: Project1.cpp file:
5
What should Go intoa .hFile
• Only declarations (i.e., info to thecompiler)
• Nothing that requiresstorage
• Reason:
• aheader file gets included in several files ofaproject;
• if storage for avariable (or for acode) is allocated multiple times, you get a
multiple-definition compilation error
• Advanced: Oneexception to this rule is static data (data local to a
file), becausethe linker does not allocate multiple instances tostatic
data.
6
RedeclarationsIssues
• An X.hfile canhave: #include “Y.h”
• Consider this scenario:
• TheX.hfile has:
#include “Y.h”
#include “Z.h”
• TheY
.hfile has: #include“Z.h”
• Thismeans: the declarations in Z.hare includedtwice
in X.h.Thesecond declarations are called
redeclarations
• Classredeclarations are not allowed.
• So,we have a problem
7
Redeclarations Issue Solution
• Inside each Z.hfile, do:
• Add to at the start of the file (right after all the #includes)the next two lines:
#ifndefZ_H_ // Not that Zis the name of .h file
#defineZ_H_
• Add the following line at the very end of Z.h(on aseparate line):
#enddef

More Related Content

Similar to Lecture 24 multiple-fileprograming.pptx

Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IDUSPviz
 
Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend developmentsparkfabrik
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twentiesPuppet
 
Twig in the wild august 2018 drupal govcon draft
Twig in the wild   august 2018 drupal govcon draftTwig in the wild   august 2018 drupal govcon draft
Twig in the wild august 2018 drupal govcon draftJeremyKoulish
 
Lecture 8_Libraries.pptx
Lecture 8_Libraries.pptxLecture 8_Libraries.pptx
Lecture 8_Libraries.pptxNelyJay
 
Custom object detection_gcp
Custom object detection_gcpCustom object detection_gcp
Custom object detection_gcpVaibhav Sahu
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptxVishuSaini22
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective cSunny Shaikh
 
Jaffle: managing processes and log messages of multiple applications in devel...
Jaffle: managing processes and log messages of multiple applicationsin devel...Jaffle: managing processes and log messages of multiple applicationsin devel...
Jaffle: managing processes and log messages of multiple applications in devel...Masaki Yatsu
 
Automating Content Import
Automating Content ImportAutomating Content Import
Automating Content ImportDavid Lippman
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Pluginsmwrather
 
C language header files
C language header filesC language header files
C language header filesmarar hina
 
Hopsworks at Google AI Huddle, Sunnyvale
Hopsworks at Google AI Huddle, SunnyvaleHopsworks at Google AI Huddle, Sunnyvale
Hopsworks at Google AI Huddle, SunnyvaleJim Dowling
 
Python advanced 3.the python std lib by example – system related modules
Python advanced 3.the python std lib by example – system related modulesPython advanced 3.the python std lib by example – system related modules
Python advanced 3.the python std lib by example – system related modulesJohn(Qiang) Zhang
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxShaownRoy1
 

Similar to Lecture 24 multiple-fileprograming.pptx (20)

Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part I
 
20-packages-jar.ppt
20-packages-jar.ppt20-packages-jar.ppt
20-packages-jar.ppt
 
Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend development
 
Persistences
PersistencesPersistences
Persistences
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
 
Twig in the wild august 2018 drupal govcon draft
Twig in the wild   august 2018 drupal govcon draftTwig in the wild   august 2018 drupal govcon draft
Twig in the wild august 2018 drupal govcon draft
 
Lecture 8_Libraries.pptx
Lecture 8_Libraries.pptxLecture 8_Libraries.pptx
Lecture 8_Libraries.pptx
 
Custom object detection_gcp
Custom object detection_gcpCustom object detection_gcp
Custom object detection_gcp
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Basic concepts of oops
Basic concepts of oopsBasic concepts of oops
Basic concepts of oops
 
Jaffle: managing processes and log messages of multiple applications in devel...
Jaffle: managing processes and log messages of multiple applicationsin devel...Jaffle: managing processes and log messages of multiple applicationsin devel...
Jaffle: managing processes and log messages of multiple applications in devel...
 
Android Data Storagefinal
Android Data StoragefinalAndroid Data Storagefinal
Android Data Storagefinal
 
Automating Content Import
Automating Content ImportAutomating Content Import
Automating Content Import
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Plugins
 
C language header files
C language header filesC language header files
C language header files
 
Hopsworks at Google AI Huddle, Sunnyvale
Hopsworks at Google AI Huddle, SunnyvaleHopsworks at Google AI Huddle, Sunnyvale
Hopsworks at Google AI Huddle, Sunnyvale
 
Python advanced 3.the python std lib by example – system related modules
Python advanced 3.the python std lib by example – system related modulesPython advanced 3.the python std lib by example – system related modules
Python advanced 3.the python std lib by example – system related modules
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 

More from AyeCS11

Topic # 26 Samba Server.pptx
Topic # 26 Samba Server.pptxTopic # 26 Samba Server.pptx
Topic # 26 Samba Server.pptxAyeCS11
 
Topic # 14 of outline Administer Local Users and Groups.pptx
Topic # 14 of outline Administer Local Users and Groups.pptxTopic # 14 of outline Administer Local Users and Groups.pptx
Topic # 14 of outline Administer Local Users and Groups.pptxAyeCS11
 
Topic # 16 of outline Managing Network Services.pptx
Topic # 16 of outline Managing Network Services.pptxTopic # 16 of outline Managing Network Services.pptx
Topic # 16 of outline Managing Network Services.pptxAyeCS11
 
Topic #3 of outline Server Environment.pptx
Topic #3 of outline Server Environment.pptxTopic #3 of outline Server Environment.pptx
Topic #3 of outline Server Environment.pptxAyeCS11
 
Topic # 12 of outline Configuring Local Services.pptx
Topic # 12 of outline Configuring Local Services.pptxTopic # 12 of outline Configuring Local Services.pptx
Topic # 12 of outline Configuring Local Services.pptxAyeCS11
 
Topic # 10 of outline SNA.pptx
Topic # 10 of outline SNA.pptxTopic # 10 of outline SNA.pptx
Topic # 10 of outline SNA.pptxAyeCS11
 
IP tables,Filtering.pptx
IP tables,Filtering.pptxIP tables,Filtering.pptx
IP tables,Filtering.pptxAyeCS11
 
Data integrity 03.pptx
Data integrity 03.pptxData integrity 03.pptx
Data integrity 03.pptxAyeCS11
 
Data and signals.ppt
Data and signals.pptData and signals.ppt
Data and signals.pptAyeCS11
 
Lec#6.ppt
Lec#6.pptLec#6.ppt
Lec#6.pptAyeCS11
 
Syllabus-Combined-Ad-No-03-2022.pdf
Syllabus-Combined-Ad-No-03-2022.pdfSyllabus-Combined-Ad-No-03-2022.pdf
Syllabus-Combined-Ad-No-03-2022.pdfAyeCS11
 

More from AyeCS11 (11)

Topic # 26 Samba Server.pptx
Topic # 26 Samba Server.pptxTopic # 26 Samba Server.pptx
Topic # 26 Samba Server.pptx
 
Topic # 14 of outline Administer Local Users and Groups.pptx
Topic # 14 of outline Administer Local Users and Groups.pptxTopic # 14 of outline Administer Local Users and Groups.pptx
Topic # 14 of outline Administer Local Users and Groups.pptx
 
Topic # 16 of outline Managing Network Services.pptx
Topic # 16 of outline Managing Network Services.pptxTopic # 16 of outline Managing Network Services.pptx
Topic # 16 of outline Managing Network Services.pptx
 
Topic #3 of outline Server Environment.pptx
Topic #3 of outline Server Environment.pptxTopic #3 of outline Server Environment.pptx
Topic #3 of outline Server Environment.pptx
 
Topic # 12 of outline Configuring Local Services.pptx
Topic # 12 of outline Configuring Local Services.pptxTopic # 12 of outline Configuring Local Services.pptx
Topic # 12 of outline Configuring Local Services.pptx
 
Topic # 10 of outline SNA.pptx
Topic # 10 of outline SNA.pptxTopic # 10 of outline SNA.pptx
Topic # 10 of outline SNA.pptx
 
IP tables,Filtering.pptx
IP tables,Filtering.pptxIP tables,Filtering.pptx
IP tables,Filtering.pptx
 
Data integrity 03.pptx
Data integrity 03.pptxData integrity 03.pptx
Data integrity 03.pptx
 
Data and signals.ppt
Data and signals.pptData and signals.ppt
Data and signals.ppt
 
Lec#6.ppt
Lec#6.pptLec#6.ppt
Lec#6.ppt
 
Syllabus-Combined-Ad-No-03-2022.pdf
Syllabus-Combined-Ad-No-03-2022.pdfSyllabus-Combined-Ad-No-03-2022.pdf
Syllabus-Combined-Ad-No-03-2022.pdf
 

Recently uploaded

Premium Call Girls Nagpur Call Girls (Adult Only) 💯Call Us 🔝 6378878445 🔝 💃 E...
Premium Call Girls Nagpur Call Girls (Adult Only) 💯Call Us 🔝 6378878445 🔝 💃 E...Premium Call Girls Nagpur Call Girls (Adult Only) 💯Call Us 🔝 6378878445 🔝 💃 E...
Premium Call Girls Nagpur Call Girls (Adult Only) 💯Call Us 🔝 6378878445 🔝 💃 E...vershagrag
 
Call Girls in Goa (Panaji) call me [🔝9701288194🔝] escort service 24X7
Call Girls in Goa (Panaji) call me [🔝9701288194🔝] escort service 24X7Call Girls in Goa (Panaji) call me [🔝9701288194🔝] escort service 24X7
Call Girls in Goa (Panaji) call me [🔝9701288194🔝] escort service 24X7jaspritkaur4u
 
Kolkata Call Girls Bengal 👉👉 0000000000 Top Class Call Girl Service Available
Kolkata Call Girls Bengal 👉👉 0000000000 Top Class Call Girl Service AvailableKolkata Call Girls Bengal 👉👉 0000000000 Top Class Call Girl Service Available
Kolkata Call Girls Bengal 👉👉 0000000000 Top Class Call Girl Service AvailableCall Girls Mumbai
 
👉Goa Call Girl Service👉📞9701288194👉📞 Just📲 Call Rajveer Call Girls Service In...
👉Goa Call Girl Service👉📞9701288194👉📞 Just📲 Call Rajveer Call Girls Service In...👉Goa Call Girl Service👉📞9701288194👉📞 Just📲 Call Rajveer Call Girls Service In...
👉Goa Call Girl Service👉📞9701288194👉📞 Just📲 Call Rajveer Call Girls Service In...Call Girls Mumbai
 
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...nirzagarg
 
Low Cost Jhansi 📞6378878445📞 Just📲 Call Inaaya Call Girls Service No💰Advance ...
Low Cost Jhansi 📞6378878445📞 Just📲 Call Inaaya Call Girls Service No💰Advance ...Low Cost Jhansi 📞6378878445📞 Just📲 Call Inaaya Call Girls Service No💰Advance ...
Low Cost Jhansi 📞6378878445📞 Just📲 Call Inaaya Call Girls Service No💰Advance ...vershagrag
 
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...gajnagarg
 
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...Dipal Arora
 
Goa🌹Vip Call Girls Panji ❤Heer 9701288194💟 Full Trusted CALL GIRLS IN Goa ESC...
Goa🌹Vip Call Girls Panji ❤Heer 9701288194💟 Full Trusted CALL GIRLS IN Goa ESC...Goa🌹Vip Call Girls Panji ❤Heer 9701288194💟 Full Trusted CALL GIRLS IN Goa ESC...
Goa🌹Vip Call Girls Panji ❤Heer 9701288194💟 Full Trusted CALL GIRLS IN Goa ESC...Call Girls Mumbai
 
What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'
What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'
What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'Euromotive Performance
 
Is Your Mercedes Benz Trunk Refusing To Close Here's What Might Be Wrong
Is Your Mercedes Benz Trunk Refusing To Close Here's What Might Be WrongIs Your Mercedes Benz Trunk Refusing To Close Here's What Might Be Wrong
Is Your Mercedes Benz Trunk Refusing To Close Here's What Might Be WrongMomentum Motorworks
 
Call Girl in Faridabad | Whatsapp No 📞 8168257667 📞 VIP Escorts Service Avail...
Call Girl in Faridabad | Whatsapp No 📞 8168257667 📞 VIP Escorts Service Avail...Call Girl in Faridabad | Whatsapp No 📞 8168257667 📞 VIP Escorts Service Avail...
Call Girl in Faridabad | Whatsapp No 📞 8168257667 📞 VIP Escorts Service Avail...Hyderabad Escorts Agency
 
FULL ENJOY 8377087607 Call Girls In Paharganj (DELHI NCr) Call Girl Service
FULL ENJOY 8377087607 Call Girls In Paharganj (DELHI NCr) Call Girl ServiceFULL ENJOY 8377087607 Call Girls In Paharganj (DELHI NCr) Call Girl Service
FULL ENJOY 8377087607 Call Girls In Paharganj (DELHI NCr) Call Girl Servicedollysharma2066
 
一比一原版西安大略大学毕业证(UWO毕业证)成绩单原件一模一样
一比一原版西安大略大学毕业证(UWO毕业证)成绩单原件一模一样一比一原版西安大略大学毕业证(UWO毕业证)成绩单原件一模一样
一比一原版西安大略大学毕业证(UWO毕业证)成绩单原件一模一样wsppdmt
 
Shimla Call Girls 💯Call Us 🔝 9xx000xx09 🔝 💃 Top Class Russian Shimla Call Gir...
Shimla Call Girls 💯Call Us 🔝 9xx000xx09 🔝 💃 Top Class Russian Shimla Call Gir...Shimla Call Girls 💯Call Us 🔝 9xx000xx09 🔝 💃 Top Class Russian Shimla Call Gir...
Shimla Call Girls 💯Call Us 🔝 9xx000xx09 🔝 💃 Top Class Russian Shimla Call Gir...Call Girls Mumbai
 
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best ServiceMuslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
Nangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi Jat
Nangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi JatNangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi Jat
Nangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi Jatmeghakumariji156
 
Kolkata🌹Vip Call Girls Bengal ❤Heer 0000000000💟 Full Trusted CALL GIRLS IN Ko...
Kolkata🌹Vip Call Girls Bengal ❤Heer 0000000000💟 Full Trusted CALL GIRLS IN Ko...Kolkata🌹Vip Call Girls Bengal ❤Heer 0000000000💟 Full Trusted CALL GIRLS IN Ko...
Kolkata🌹Vip Call Girls Bengal ❤Heer 0000000000💟 Full Trusted CALL GIRLS IN Ko...Call Girls Mumbai
 
Amreli } Russian Call Girls Ahmedabad - Phone 8005736733 Escorts Service at 6...
Amreli } Russian Call Girls Ahmedabad - Phone 8005736733 Escorts Service at 6...Amreli } Russian Call Girls Ahmedabad - Phone 8005736733 Escorts Service at 6...
Amreli } Russian Call Girls Ahmedabad - Phone 8005736733 Escorts Service at 6...gragchanchal546
 

Recently uploaded (20)

Premium Call Girls Nagpur Call Girls (Adult Only) 💯Call Us 🔝 6378878445 🔝 💃 E...
Premium Call Girls Nagpur Call Girls (Adult Only) 💯Call Us 🔝 6378878445 🔝 💃 E...Premium Call Girls Nagpur Call Girls (Adult Only) 💯Call Us 🔝 6378878445 🔝 💃 E...
Premium Call Girls Nagpur Call Girls (Adult Only) 💯Call Us 🔝 6378878445 🔝 💃 E...
 
Obat Penggugur Kandungan Di Apotek Klinik Banyuwangi +6287776558899
Obat Penggugur Kandungan Di Apotek Klinik Banyuwangi +6287776558899Obat Penggugur Kandungan Di Apotek Klinik Banyuwangi +6287776558899
Obat Penggugur Kandungan Di Apotek Klinik Banyuwangi +6287776558899
 
Call Girls in Goa (Panaji) call me [🔝9701288194🔝] escort service 24X7
Call Girls in Goa (Panaji) call me [🔝9701288194🔝] escort service 24X7Call Girls in Goa (Panaji) call me [🔝9701288194🔝] escort service 24X7
Call Girls in Goa (Panaji) call me [🔝9701288194🔝] escort service 24X7
 
Kolkata Call Girls Bengal 👉👉 0000000000 Top Class Call Girl Service Available
Kolkata Call Girls Bengal 👉👉 0000000000 Top Class Call Girl Service AvailableKolkata Call Girls Bengal 👉👉 0000000000 Top Class Call Girl Service Available
Kolkata Call Girls Bengal 👉👉 0000000000 Top Class Call Girl Service Available
 
👉Goa Call Girl Service👉📞9701288194👉📞 Just📲 Call Rajveer Call Girls Service In...
👉Goa Call Girl Service👉📞9701288194👉📞 Just📲 Call Rajveer Call Girls Service In...👉Goa Call Girl Service👉📞9701288194👉📞 Just📲 Call Rajveer Call Girls Service In...
👉Goa Call Girl Service👉📞9701288194👉📞 Just📲 Call Rajveer Call Girls Service In...
 
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
 
Low Cost Jhansi 📞6378878445📞 Just📲 Call Inaaya Call Girls Service No💰Advance ...
Low Cost Jhansi 📞6378878445📞 Just📲 Call Inaaya Call Girls Service No💰Advance ...Low Cost Jhansi 📞6378878445📞 Just📲 Call Inaaya Call Girls Service No💰Advance ...
Low Cost Jhansi 📞6378878445📞 Just📲 Call Inaaya Call Girls Service No💰Advance ...
 
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
 
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
 
Goa🌹Vip Call Girls Panji ❤Heer 9701288194💟 Full Trusted CALL GIRLS IN Goa ESC...
Goa🌹Vip Call Girls Panji ❤Heer 9701288194💟 Full Trusted CALL GIRLS IN Goa ESC...Goa🌹Vip Call Girls Panji ❤Heer 9701288194💟 Full Trusted CALL GIRLS IN Goa ESC...
Goa🌹Vip Call Girls Panji ❤Heer 9701288194💟 Full Trusted CALL GIRLS IN Goa ESC...
 
What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'
What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'
What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'
 
Is Your Mercedes Benz Trunk Refusing To Close Here's What Might Be Wrong
Is Your Mercedes Benz Trunk Refusing To Close Here's What Might Be WrongIs Your Mercedes Benz Trunk Refusing To Close Here's What Might Be Wrong
Is Your Mercedes Benz Trunk Refusing To Close Here's What Might Be Wrong
 
Call Girl in Faridabad | Whatsapp No 📞 8168257667 📞 VIP Escorts Service Avail...
Call Girl in Faridabad | Whatsapp No 📞 8168257667 📞 VIP Escorts Service Avail...Call Girl in Faridabad | Whatsapp No 📞 8168257667 📞 VIP Escorts Service Avail...
Call Girl in Faridabad | Whatsapp No 📞 8168257667 📞 VIP Escorts Service Avail...
 
FULL ENJOY 8377087607 Call Girls In Paharganj (DELHI NCr) Call Girl Service
FULL ENJOY 8377087607 Call Girls In Paharganj (DELHI NCr) Call Girl ServiceFULL ENJOY 8377087607 Call Girls In Paharganj (DELHI NCr) Call Girl Service
FULL ENJOY 8377087607 Call Girls In Paharganj (DELHI NCr) Call Girl Service
 
一比一原版西安大略大学毕业证(UWO毕业证)成绩单原件一模一样
一比一原版西安大略大学毕业证(UWO毕业证)成绩单原件一模一样一比一原版西安大略大学毕业证(UWO毕业证)成绩单原件一模一样
一比一原版西安大略大学毕业证(UWO毕业证)成绩单原件一模一样
 
Shimla Call Girls 💯Call Us 🔝 9xx000xx09 🔝 💃 Top Class Russian Shimla Call Gir...
Shimla Call Girls 💯Call Us 🔝 9xx000xx09 🔝 💃 Top Class Russian Shimla Call Gir...Shimla Call Girls 💯Call Us 🔝 9xx000xx09 🔝 💃 Top Class Russian Shimla Call Gir...
Shimla Call Girls 💯Call Us 🔝 9xx000xx09 🔝 💃 Top Class Russian Shimla Call Gir...
 
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best ServiceMuslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
 
Nangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi Jat
Nangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi JatNangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi Jat
Nangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi Jat
 
Kolkata🌹Vip Call Girls Bengal ❤Heer 0000000000💟 Full Trusted CALL GIRLS IN Ko...
Kolkata🌹Vip Call Girls Bengal ❤Heer 0000000000💟 Full Trusted CALL GIRLS IN Ko...Kolkata🌹Vip Call Girls Bengal ❤Heer 0000000000💟 Full Trusted CALL GIRLS IN Ko...
Kolkata🌹Vip Call Girls Bengal ❤Heer 0000000000💟 Full Trusted CALL GIRLS IN Ko...
 
Amreli } Russian Call Girls Ahmedabad - Phone 8005736733 Escorts Service at 6...
Amreli } Russian Call Girls Ahmedabad - Phone 8005736733 Escorts Service at 6...Amreli } Russian Call Girls Ahmedabad - Phone 8005736733 Escorts Service at 6...
Amreli } Russian Call Girls Ahmedabad - Phone 8005736733 Escorts Service at 6...
 

Lecture 24 multiple-fileprograming.pptx

  • 1. Multiple-FilePrograms, Inheritance,Templates •Multiple-File Programs • header files • implementation files • main-program file) 1
  • 2. 2 Why MultipleFiles • Re-use • Better data abstraction (datahiding) • More manageability of largeprograms
  • 3. 3 The Multiple-FileApproach • Haveeach major classasaseparate program • Re-use:Theclasscanthen be used by other programs using the #include macro instead of the copy-&-pasteapproach • Put the class/function declarations in a header (.h) file, and the class/function implementations in another (.c or .cpp) file. This achieves data hiding.
  • 4. 4 Example class Stack{ public: typedef int dtype; Stack(int cap=100); int getCapacity(); void push(dtypeb); dtype pop(); dtype peek(); bool isEmpty(); private: dtype *dataptr; int top; int capacity; }; #include"Stack.h" Stack::Stack(intcap){ top=0; capacity =(cap>0)?cap:100; dataptr =newint[capacity]; }; int Stack::getCapacity( ) { return capacity; }; int Stack::dtype Stack::pop(){ assert(!isEmpty()); returndataptr[--top]; }; // the implementation of // the remaining methods ........ #include <cstdlib> #include<iostream> #include"Stack.h” using namespacestd; // local stuff,ifany int main(intargc, char*argv[]){ ……… } Stack.hfile: Stack.cpp file: Project1.cpp file:
  • 5. 5 What should Go intoa .hFile • Only declarations (i.e., info to thecompiler) • Nothing that requiresstorage • Reason: • aheader file gets included in several files ofaproject; • if storage for avariable (or for acode) is allocated multiple times, you get a multiple-definition compilation error • Advanced: Oneexception to this rule is static data (data local to a file), becausethe linker does not allocate multiple instances tostatic data.
  • 6. 6 RedeclarationsIssues • An X.hfile canhave: #include “Y.h” • Consider this scenario: • TheX.hfile has: #include “Y.h” #include “Z.h” • TheY .hfile has: #include“Z.h” • Thismeans: the declarations in Z.hare includedtwice in X.h.Thesecond declarations are called redeclarations • Classredeclarations are not allowed. • So,we have a problem
  • 7. 7 Redeclarations Issue Solution • Inside each Z.hfile, do: • Add to at the start of the file (right after all the #includes)the next two lines: #ifndefZ_H_ // Not that Zis the name of .h file #defineZ_H_ • Add the following line at the very end of Z.h(on aseparate line): #enddef