sysprog 7
TRANSCRIPT
C/C++ For Linux
Session 7C++ - Session 1
Outline
● Why C++?● New easier way to code old concepts● Classes ● More on old concepts renewed● Automake example
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?
Central Axes of our Discussion
● Abstraction/hiding made easier● Object behavior modification
– common/specific
● Generic programming – type independence
● Inter-object interaction – Design
References
● An object naming● Declaration● Lvalue assignment from const, non-const
Remember Functions?
● Overloading– Function signature
– const
● Default arguments– Ambiguity with overloading
Remember Scopes?
● Namespaces– A scope unrelated to any instances
– Declaration
– Using
● Scoping operator● Can be nested
Class
● An object type● A scope
Class as Object type
● Define behavior/interface:– Member variables
– Member methods
– Can define creation/deletion behavior
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
Creation/Deletion
● Constructors● Destructors● How they get invoked
– Declaration
– scoping
● Malloc/free with an attitude:– new
– delete
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.
Structures with an attitude
● Now object types● Now have member methods
– No access level
● Anonymous structures and unions● To be continued
Automake example
● Write your code● Makefile.am
– SUBDIRS
– Building Libraries
– Building executables● Linking against your library● Including your headers
● autoscan
Automake example-cont'd
● Modify output– Rename to configure.ac
– AM_INIT_AUTOMAKE
– AC_PROG_LIBTOOL
● autoreconf --install● ./configure● Make