Sung-Min%20Jung - PowerPoint PPT Presentation

About This Presentation
Title:

Sung-Min%20Jung

Description:

Title: PowerPoint Presentation Last modified by: user Created Date: 1/1/1601 12:00:00 AM Document presentation format: Other titles – PowerPoint PPT presentation

Number of Views:94
Avg rating:3.0/5.0
Slides: 19
Provided by: tist271
Category:
Tags: 20jung | min | sung

less

Transcript and Presenter's Notes

Title: Sung-Min%20Jung


1
10? ??? ????
  • Sung-Min Jung
  • Internet Management Technology Lab.
  • School of Information Communication
    Engineering,
  • Sungkyunkwan Univ.
  • 300 Cheoncheon-dong, Jangan-gu, Suwon-si,
    Gyeonggi-do, Korea.
  • Tel 82-31-290-7222, Fax 82-31-299-6673
  • smjung_at_imtl.skku.ac.kr

2
10-1 ??? ????? ??
class Point private int x, y public
Point(int _x0, int _y0)x(_x), y(_y) void
ShowPosition() void operator(int
val) void PointShowPosition()
coutltltxltlt" "ltltyltltendl void
Pointoperator(int val) xval
yval
int main(void) Point p(3, 4)
p.ShowPosition() p.operator(10)
p.ShowPosition() return 0
3
10-2 ??? ???? ? ?? ??
  • ?? ??? ?? ????

class Point private int x, y public
Point(int _x0, int _y0)x(_x), y(_y) void
ShowPosition() Point operator(const Point
p) void PointShowPosition()
coutltltxltlt" "ltltyltltendl Point
Pointoperator(const Point p) Point
temp(xp.x, yp.y) return temp
int main(void) Point p1(1, 2) Point
p2(2, 1) Point p3p1p2
p3.ShowPosition() return 0
4
10-2 ??? ???? ? ?? ??
  • ?? ??? ?? ????

class Point private int x, y public
Point(int _x0, int _y0)x(_x), y(_y) void
ShowPosition() friend Point operator(const
Point, const Point) void PointShowPosition
() coutltltxltlt" "ltltyltltendl Point
operator(const Point p1, const Point p2)
Point temp(p1.xp2.x, p1.yp2.y) return
temp
int main(void) Point p1(1, 2) Point
p2(2, 1) Point p3p1p2
p3.ShowPosition() return 0
5
10-2 ??? ???? ? ?? ??
  • ??? ????? ?? ??
  • ? ??? ??? ??? ????!
  • ??? ?? ??? ???? ????.
  • ??? ???? ??? ?????.
  • ??? ????? ?? ?? ?? ??

int operator(int a, int b) // ?? ???? ??
return ab3
6
10-3 ?? ???? ????
  • ??, ?? ??? ????

?? 10-7
7
10-3 ?? ???? ????
class Point private int x, y public
Point(int _x0, int _y0)x(_x), y(_y) void
ShowPosition() Point operator()
friend Point operator--(Point p) void
PointShowPosition() coutltltxltlt"
"ltltyltltendl Point Pointoperator()
x y return this Point
operator--(Point p) p.x-- p.y--
return p
int main(void) Point p(1, 2) p
//p? x, y ?? 1? ?? p.ShowPosition() //2,
3 --p //p? x, y ?? 2? ??
p.ShowPosition() //1, 2 (p)
p.ShowPosition() //3, 4 --(--p)
p.ShowPosition() //1, 2 return 0
8
10-3 ?? ???? ????
  • ? ??? ? ??? ??

p ? p.operator() p ?
p.operator(int)
--p ? p.operator--() p-- ?
p.operator--(int)
9
10-3 ?? ???? ????
class Point private int x, y public
Point(int _x0, int _y0)x(_x), y(_y)
void ShowPosition() Point operator()
Point operator(int) void PointShowPosition
() coutltltxltlt" "ltltyltltendl Point
Pointoperator() x y return
this Point Pointoperator(int) Point
temp(x, y) // Point temp(this) x
y return temp
int main(void) Point p1(1, 2)
(p1).ShowPosition() p1.ShowPosition()
Point p2(1, 2) (p2).ShowPosition()
return 0
10
10-4 ?? ?? ????
  • ?? ??? ??
  • Associative1.cpp
  • Associative2.cpp

?? 10-9
11
10-4 ?? ?? ????
  • ?? ??? ??
  • TempObj.cpp
  • ?? ?? ??? ??
  • Associative2.cpp? ??

Point(3, 4)
Point Pointoperator(int val) return
Point(xval, yval)
12
10-5 cout, cin ??? endl? ??
includeltstdio.hgt namespace mystd //mystd?? ????
?? char endl"\n" class ostream //
??? ostream ?? public ostream
operatorltlt(char str) printf("s", str)
return this ostream
operatorltlt(int i) printf("d", i) return
this ostream operatorltlt(double
i) printf("e", i) return this
ostream cout //ostream ?? ??
// mystd ???? ?
using mystdcout using mystdendl int
main() coutltlt"Hello World"ltltendlltlt3.14ltltendl
return 0
13
10-5 cout, cin ??? endl? ??
  • ltlt, gtgt ???? ????
  • Point ??? ???? ?? ltlt, gtgt ? ?? ??
  • OpOverloading6.cpp

coutltltp ? cout.operatorltlt(p) // (x)
coutltltp ? operatorltlt(cout, p) // (o)
ostream operatorltlt(ostream os, const Point p)
14
10-6 ??? ???
  • ?? ??? ??? ?? ?? ???
  • IdxOverloading1.cpp
  • ?? ??? ? ?? ?? ???
  • IdxOverloading2.cpp

arri ? arr.operator(i)
15
10-7 ?? ??? ????
  • ??? ?? ???
  • ?? ? ?? ??
  • DefaultSubOp.cpp

p1.operator(p2)
Point Pointoperator(const Point p)
xp.x yp.y return this
16
10-7 ?? ??? ????
  • ??? ?? ???? ???

class Person private char name public
Person(char _name) Person(const Person
p) Person() friend ostream
operatorltlt(ostream os, const Person
p) PersonPerson(char _name) name
new charstrlen(_name)1 strcpy(name,
_name) PersonPerson(const Person p)
name new charstrlen(p.name)1
strcpy(name, p.name) PersonPerson()
delete name
int main() Person p1("LEE JUNE") Person
p2("HONG KEN") coutltltp1ltltendl
coutltltp2ltltendl p1p2 // ??? ??
coutltltp1ltltendl return 0
17
10-7 ?? ??? ????
  • ??? ?? ???? ???

?? 10-13
?? 10-14
18
10-7 ?? ??? ????
  • ?? ??(Deep Copy)? ?? ?? ???

Person Personoperator(const Person p)
delete name name new charstrlen(p.name)1
strcpy(name, p.name) return this
Write a Comment
User Comments (0)
About PowerShow.com