sysprog 7

15

Click here to load reader

Upload: ahmed-mekkawy

Post on 03-Jul-2015

515 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Sysprog 7

C/C++ For Linux

Session 7C++ - Session 1

Page 2: Sysprog 7

Outline

● Why C++?● New easier way to code old concepts● Classes ● More on old concepts renewed● Automake example

Page 3: Sysprog 7

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

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

References

● An object naming● Declaration● Lvalue assignment from const, non-const

Page 6: Sysprog 7

Remember Functions?

● Overloading– Function signature

– const

● Default arguments– Ambiguity with overloading

Page 7: Sysprog 7

Remember Scopes?

● Namespaces– A scope unrelated to any instances

– Declaration

– Using

● Scoping operator● Can be nested

Page 8: Sysprog 7

Class

● An object type● A scope

Page 9: Sysprog 7

Class as Object type

● Define behavior/interface:– Member variables

– Member methods

– Can define creation/deletion behavior

Page 10: Sysprog 7

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

Creation/Deletion

● Constructors● Destructors● How they get invoked

– Declaration

– scoping

● Malloc/free with an attitude:– new

– delete

Page 12: Sysprog 7

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

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

Automake example

● Write your code● Makefile.am

– SUBDIRS

– Building Libraries

– Building executables● Linking against your library● Including your headers

● autoscan

Page 15: Sysprog 7

Automake example-cont'd

● Modify output– Rename to configure.ac

– AM_INIT_AUTOMAKE

– AC_PROG_LIBTOOL

● autoreconf --install● ./configure● Make