Sysprog 7
Click here to load reader
-
Upload
ahmed-mekkawy -
Category
Technology
-
view
515 -
download
0
Transcript of Sysprog 7
![Page 1: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/1.jpg)
C/C++ For Linux
Session 7C++ - Session 1
![Page 2: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/2.jpg)
Outline
● Why C++?● New easier way to code old concepts● Classes ● More on old concepts renewed● Automake example
![Page 3: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/3.jpg)
Object-Oriented Concepts
● Instance vs type● Isa● Not centered on procedure (flow control)● Centered on object: flow possibilities explode
on global level● Consider IPC example – is OO doable in C?
![Page 4: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/4.jpg)
Central Axes of our Discussion
● Abstraction/hiding made easier● Object behavior modification
– common/specific
● Generic programming – type independence
● Inter-object interaction – Design
![Page 5: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/5.jpg)
References
● An object naming● Declaration● Lvalue assignment from const, non-const
![Page 6: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/6.jpg)
Remember Functions?
● Overloading– Function signature
– const
● Default arguments– Ambiguity with overloading
![Page 7: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/7.jpg)
Remember Scopes?
● Namespaces– A scope unrelated to any instances
– Declaration
– Using
● Scoping operator● Can be nested
![Page 8: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/8.jpg)
Class
● An object type● A scope
![Page 9: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/9.jpg)
Class as Object type
● Define behavior/interface:– Member variables
– Member methods
– Can define creation/deletion behavior
![Page 10: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/10.jpg)
Class as a Scope
● Private - Not accessible from outside that class● Public - Accessible from outside the class● :: on class-wide things● .,-> on instance● Enumerations, consts, nested
classes/structures
![Page 11: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/11.jpg)
Creation/Deletion
● Constructors● Destructors● How they get invoked
– Declaration
– scoping
● Malloc/free with an attitude:– new
– delete
![Page 12: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/12.jpg)
Static Members
● Class-wide, do not operate on an instance● “public”ness still applies (outside initialization)● Variables must be initialized● Methods can not operate on an instance, i.e.
can not access non-static members.
![Page 13: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/13.jpg)
Structures with an attitude
● Now object types● Now have member methods
– No access level
● Anonymous structures and unions● To be continued
![Page 14: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/14.jpg)
Automake example
● Write your code● Makefile.am
– SUBDIRS
– Building Libraries
– Building executables● Linking against your library● Including your headers
● autoscan
![Page 15: Sysprog 7](https://reader038.fdocuments.net/reader038/viewer/2022100518/55961bc91a28ab94018b45b7/html5/thumbnails/15.jpg)
Automake example-cont'd
● Modify output– Rename to configure.ac
– AM_INIT_AUTOMAKE
– AC_PROG_LIBTOOL
● autoreconf --install● ./configure● Make