void A - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

void A

Description:

g -c prog.cc. g -c procA.cc o test.o. g prog.o test.o o prog. Separate compilation. For every class have a separate .h file for the declarations. ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 19
Provided by: sharonk90
Category:

less

Transcript and Presenter's Notes

Title: void A


1
  • void A()
  • cout ltlt hello ltlt endl
  • int main()
  • A()
  • return(0)

2
  • include ltfstream.hgt
  • void A()
  • int main()
  • A()
  • return(0)
  • Saved this file as prog.cc

3
  • include ltfstream.hgt
  • void A()
  • cout ltlt hello ltlt endl
  • Saved this code in procA.cc

4
  • include ltfstream.hgt
  • void A()
  • int main()
  • A()
  • return(0)
  • I did not do an include in this example but
    simply compiled both CC files and linked
    together.
  • g -c prog.cc
  • g -c procA.cc o test.o
  • g prog.o test.o o prog

5
  • Separate compilation
  • For every class have a separate .h file for the
    declarations.
  • Have a separate .cc file for the class
    definitions.
  • Have a separate .cc file for the main program or
    driver program.

6
  • class A
  • public
  • A()
  • int n
  • Saved as classa.h

7
  • include "classa.h"
  • AA()
  • n 42
  • Saved as classa.cc

8
  • include "classa.h"
  • class B
  • public
  • B()
  • A a,b
  • B has a relationship with A
  • Saved as classb.h

9
  • include "classb.h"
  • BB()
  • a.n 17
  • b.n 18
  • Saved as classb.cc

10
  • include ltfstream.hgt
  • include "classb.h"
  • int main()
  • B x
  • cout ltlt x.a.n ltlt endl
  • Saved as prog.cc

11
  • g -c Wall Werror classa.cc
  • g -c Wall Werror classb.cc
  • g -c Wall Werror prog.cc
  • g -o progtest classa.o classb.o prog.o

12
  • include ltfstream.hgt
  • include "classb.h"
  • include "classa.h"
  • int main()
  • B x
  • cout ltlt x.a.n ltlt endl

13
  • ifndef A_H
  • define A_H
  • class A
  • public
  • A()
  • int n
  • endif
  • If a.h is not defined do everything up to it, if
    it is defined skip over to the endif

14
  • Make Facility
  • A UNIX command that looks for a file called
    Makefile or makefile.
  • emacs Makefile
  • Executes the first command in the file.
  • Comments begin with
  • ltstringgt
  • lttabgt some command
  • lttabgt some command

15
  • Make Facility
  • prog a.o b.o prog.o
  • g -o prog a.o b.o prog.o
  • prog is known as a target
  • a.o b.o prog.o are known as dependencies
  • When the target prog is called, it first checks
    to see if the dependencies are present, if they
    have a newer date then prog or if they are a
    target.

16
  • Make Facility
  • prog a.o b.o prog.o
  • g -o prog a.o b.o prog.o
  • a.o a.cc a.h
  • g -c Wall Werror a.cc
  • prog.o prog.cc b.h a.h
  • g -c Wall Werror prog.cc
  • b.o b.cc b.h
  • g -c Wall Werror b.cc
  • clean
  • rm f .o prog

17
  • Make Facility

make a.o make b.o make prog.o make clean
18
  • Make Facility
  • Edit a file a.h b.h a.cc b.cc prog.cc then by
    running make it will recompile and link.
  • Macros can be used to put a string within a
    command.
  • OPTIONS -c Wall Werror
  • a.o a.cc a.h
  • g (options) a.cc
Write a Comment
User Comments (0)
About PowerShow.com