๋Œ€์ž… ์—ฐ์‚ฐ์ž

ยทC++/๊ธฐํƒ€
์ €๋ฒˆ ํฌ์ŠคํŠธ์—์„œ ๋‹ค๋ฃฌ ๋ณต์‚ฌ ๋ฐฉ์‹์˜ ๋Œ€์ž… ์—ฐ์‚ฐ์ž ์˜ค๋ฒ„๋กœ๋”ฉ์€ l-value์— ๋Œ€ํ•ด์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ ํฌ์ŠคํŠธ์—์„œ ๋‹ค๋ฃฐ ์ด๋™ ๋Œ€์ž… ์—ฐ์‚ฐ์ž ์˜ค๋ฒ„๋กœ๋”ฉ์€ r-value๋ฅผ ๋‹ค๋ฃน๋‹ˆ๋‹ค. ๋‹ค์Œ ์ฝ”๋“œ ์กฐ๊ฐ์„ ์‚ดํŽด๋ด…์‹œ๋‹ค. Mystring s1; s1 = Mystring{"Ricky"};// Move Assignment ์—ฌ๊ธฐ์„œ empty string์„ ๋‹ด๋Š” Mystring ๊ฐ์ฒด s1์„ ์„ ์–ธํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  s1์— Mystring{"Ricky"}๋ฅผ ํ†ตํ•ด์„œ Ricky๋ผ๋Š” ๋ฌธ์ž์—ด์„ ์†์„ฑ์œผ๋กœ ์ง€๋‹Œ Mystring ๊ฐ์ฒด๋ฅผ ํ• ๋‹นํ–ˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ์ ์€, s1์— ๊ฐ’์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ƒˆ๋กœ์šด ์ด๋ฆ„ ์—†๋Š” ์ž„์‹œ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ , ๊ทธ ๊ฐ’์„ s1์— ์ €์žฅ์„ ํ•œ ๋’ค์— ์ž„์‹œ ๊ฐ์ฒด๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์ด r-value ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์•„์‹œ๋‹ค์‹œํ”ผ ์ด๋Ÿฐ..
Chan Lee
'๋Œ€์ž… ์—ฐ์‚ฐ์ž' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก