?a???s?as? t?? PowerPoint - PowerPoint PPT Presentation

About This Presentation
Title:

?a???s?as? t?? PowerPoint

Description:

– PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 16
Provided by: UserS188
Category:

less

Transcript and Presenter's Notes

Title: ?a???s?as? t?? PowerPoint


1
??t??e?µe??st?ef?? ?????aµµat?sµ??
???S??S ??
2
?pe?f??t?s? (Overloading)
?ta? t? ?d?? ???µa s????t?s?? (µe??d??)
???s?µ?p??e?ta? ??a pe??ss?te?e? ap? µ?a
s??a?t?se?? (µe??d???) t?te t? ???µa ?e??e?ta?
?pe?f??t?µ???. St? C ta ???µata t??
s??a?t?se?? µp??e? ?a ?pe?f??t?????, ded?µ????
?t? ?? t?p?? t?? pa?aµ?t??? e??a?
d?af??et????. G?a pa??de??µa µp??e?te ?a d???sete
d?? s??a?t?se?? void print(Employee e)
// void print(Time t) // ?ta?
?a?e?ta? ? s????t?s? print(x) ? µeta???tt?st??
ap?fas?se? ß?se? t?? t?p?? t?? ???sµ?t?? p??a
s????t?s? ?a ?a??se?. ?? ?a? e??a? ?a?? ?a
???s?µ?p?????ta? d?af??et??? ???µata ??a t??
µe??d??? µ?a? ???s??, ? ?pe?f??t?s? e??a?
a?a??a?a st?? pe??pt?s? p????? ?atas?e?ast??. ?p?p
???? st? C ?p???e? ? d??at?t?ta ?pe?f??t?s??
te?est?? (, , ltlt) a??e? ??a? ap? t???
te?est???? ?a e??a? a?t??e?µe?? ??p??a? ???s??.
3
Sta?e?? (const) a?t??e?µe?a ?a? µ???d??
  • Principle of least priviledge
  • Sta a?t??e?µe?a p??pe? ?a d????ta? µ??? ta
    d??a??µata p?? ??e?????ta?, ?a? ??? pe??ss?te?a
    (p.?. ???sµ??a a?t??e?µe?a p??pe? ?a e??a?
    t??p?p???s?µa ?a? ???a ???)
  • ???sd????st?? const
  • ???sd?????e? ?t? ??a a?t??e?µe?? de? µp??e? ?a
    t??p?p????e?
  • ?p??ad?p?te ap?pe??a t??p?p???s?? e??a?
    s??ta?t??? ?????
  • ?a??de??µa
  • const Time noon( 12, 0, 0 )
  • ?????e? ??a sta?e?? (const) a?t??e?µe?? noon t??
    ???s?? Time ?a? t? a?????p??e?
  • - ?? µeta???tt?st?? t?? C de? ep?t??p???
    ?p??ad?p?te ???s? se const a?t??e?µe?a, e?t??
    µ?s? µe??d?? p?? e??a? d???µ??e? const

4
Sta?e?? (const) a?t??e?µe?a ?a? µ???d??
  • const a?t??e?µe?a apa?t??? const µe??d???
  • ?? µ???d?? p?? e??a? d???µ??e? const de? µp?????
    ?a t??p?p???s??? t? a?t??e?µe?? t???
  • ? p??sd????st?? const p??pe? ?a p??ste?e? st?
    d???s? t?? µe??d?? ?a? st?? ???sµ? t??
  • ???t?t?p?
  • ReturnType FunctionName(param1,param2) const
  • ???sµ??
  • ReturnType FunctionName(param1,param2) const
  • ?a??de??µa
  • int AgetValue() const return privateDataMember
  • ?p?st??fe? t?? t?µ? e??? µ????? ded?µ???? a???
    de? t??p?p??e? t?p?ta ?a? ?at? s???pe?a d????eta?
    const
  • - ?? ?atas?e?ast?? de? µp????? ?a e??a? const
  • - ??e???eta? ?a a?????p????? µetaß??t?? ?a? ?at?
    s???pe?a ?a t?? t??p?p?????

5
S????e? Sf??µa
  • ??e? ?? µ???d?? p??sßas?? ?a p??pe? ?a
    d??????ta? const
  • class Product
  • . . .
  • void print() const
  • . . .
  • ?? de? t????e? a?t?? ? ?a???a? p??a??? ?a
    d?µ?????????? ???se?? p?? de? µp????? ?a
    epa?a???s?µ?p???????. ?st? ?t? ? print de?
    d????eta? const ?a? ??p???? ????? p????aµµat?st??
    ???s?µ?p??e? t?? Product

6
F?????? S??a?t?se?? (Friend Functions)
  • F?????? (friend) s??a?t?se?? ?a? f?????? ???se??
  • ?p????? ?a p??spe??s??? private (?a? protected)
    µ??? µ?a? ????? ???s??
  • ?? friend s??a?t?se?? de? e??a? µ???d?? t??
    ???s??
  • ???????ta? ??? ap? t? ped?? eµß??e?a? µ?a?
    ???s??
  • ?p????? ?a ße?t??s??? se ???sµ??e? pe??pt?se??
    t?? ta??t?ta (p.?. µ?a f????? ???s? µp??e? ?a
    d?at???e? ta a?t??e?µe?a µ?a? pe????e???sa?
    (container) ???s??
  • ?d??t?te? t?? f???a?
  • ? f???a pa???eta?, de? ap??t?ta?
  • ?? s?µµet???? (a? B e??a? friend t?? A, ? A de?
    e??a? ?at a????? friend t?? B)
  • ?? µetaßat??? (a? A e??a? friend t?? B, B e??a?
    friend t?? C, A de? e??a? ?at a????? friend t??
    C)

7
F?????? S??a?t?se?? (Friend Functions)
  • ????s? f?????? ???se??/s??a?t?se??
  • G?a ?a d????e? µ?a friend s????t?s?
  • ??sa???? t?? desµe?µ???? ????? friend p??? t?
    p??t?t?p? t?? s????t?s?? st?? ???s? p?? pa???e?
    t? f???a
  • friend int myFunction( int x )
  • G?a ?a d????e? µ?a friend ???s?
  • ??sa???? t?? friend class Classname st?? ???s?
    p?? pa???e? t? f???a
  • a? ? ClassOne pa???e? f???a st?? ClassTwo,
  • friend class ClassTwo
  • ?a p??pe? ?a eµfa???eta? st?? ???sµ? t??
    ClassOne
  • G?a p?????? st?? ??-?????t?ta, ? f???a
    ?e??e?ta? ?t? ?atast??fe? t?? e?s?µ?t?s? ?a? t??
    ap?????? p????f???a? µe?????ta? t?? a??a t??
    a?t??e?µe??st?af??? s?ed???

8
Stat??? (static) ????
  • ???e a?t??e?µe?? µ?a? ???s?? ??e? ta d??? t??
    a?t???afa t?? µe??? ded?µ????
  • Se ???sµ??e? pe??pt?se?? ??a µ??? a?t???af?
    p??pe? ?a µ?????eta? µeta?? ???? t?? a?t??e?µ????
  • Video Game with Martians
  • ???e Martian ???eta? de???? a? ?? Martians
    ?????? ????te??? ap? 5
  • s??ep??, ???e Martian p??pe? ?a ??????e? t?
    martianCount
  • spat??? ??????/????? a? ???e a?t??e?µe?? Martian
    ??e? d??? t?? a?t???af? t?? martianCount
  • st?? pe??pt?s? a?t? ? martianCount e??a?
    ap?d?t??? ?a d????e? static

9
Stat??? (static) ????
  • - ?a???? p?? µ??????? µe ?a??????? µetaß??t??
    ????? ped?? eµß??e?a? t?? ???s?
  • ??????p?????ta? µ?a µ??? f??? se file scope (???
    ap? ?p??ad?p?te s????t?s?)
  • ?f?sta?ta? a??µ? ?a? a? de? ?p?????? a?t??e?µe?a
    t?? ???s??
  • ??s? µetaß??t?? ?s? ?a? s??a?t?se?? µp??e? ?a
    e??a? static
  • ?p????? ?a e??a? public, private ? protected
  • public static variables
  • ?p????? ?a p??spe?ast??? ???s?µ?p????ta? t??
    scope resolution operator()
  • Employeecount
  • private static variables
  • ?? de? ?p???e? a?t??e?µe?? t?? ???s??, µp?????
    ?a p??spe?ast??? µ??? µ?s? public static µe??d??
  • G?a t?? ???s? µ?a? public static µe??d??
    s??d???eta? t? ???µa t?? ???s??, ? te?est??
    ?a? t? ???µa t?? µe??d??
  • EmployeegetCount()

10
(No Transcript)
11
(No Transcript)
12
(No Transcript)
13
(No Transcript)
14
Number of employees before instantiation is
0 Employee constructor for Susan Baker
called. Employee constructor for Robert Jones
called. Number of employees after instantiation
is 2   Employee 1 Susan Baker Employee 2 Robert
Jones  
15
S???es? ??t??e?µe?a ?? µ??? ded?µ????
  • S???es?
  • ??a ???s? µp??e? ?a ??e? a?t??e?µe?a ?????
    ???se?? ?? ?d??t?te?
  • ?a??de??µa

class Employee public Employee(string name,
int bDay, int bMonth,
int bYear) private string lastName
const Date birthDate
class Date public Date(int day, int month,
int year) void print() const private int
month int day int year
EmployeeEmployee(string name, int bDay,int
bMonth, int bYear) birthDate(bDay, bMonth,
bYear) lastName name
Write a Comment
User Comments (0)
About PowerShow.com