^_^ 맞는지는 모르겠지만 일단 씁니다.
----
foo b(1);이 호출 될 때에 foo의 생성자 foo(int aa); 가 호출되면서 ctor이 출력됩니다.
what(b); 가 호출될 때 참조가 아닌 값의 전달이 일어나면서 복사 생성자가 호출됩니다. (b가 arg로 복사 될때) 복사 생성자가 없기 때문에 기본 복사 생성자가 호출됩니다.
what함수가 끝날 때 arg가 사라지므로 소멸자 호출
TestFixedlist가 호출될때 b가 사라지므로 소멸자 호출
그러므로 ctor은 한번 dtor은 두번 호출됩니다.
복사생성자를 추가하면 두번 호출되겠죠
foo(foo &f) { puts("ctor"); }
2003.07.14 14:48:43 (*.49.108.126)
neolith
딩동댕 ^^.. 저랑 모 님은 이것때문에 아침 나절을 stl 을 의심하면서 시간낭비했었다는..
2003.07.15 00:10:51 (*.74.195.168)
snowflower
^_^)v
2003.07.15 04:50:43 (*.72.38.135)
브루펜시럽
우앙.. 스터디때 배운거닥.. 뭔가 뿌듯함이.. >.<
2003.07.15 13:50:39 (*.152.150.69)
검은고래
난 헛배웠어..;;
2003.07.15 14:00:07 (*.114.22.114)
민스
난 모르겟어..;;
2003.07.16 11:03:44 (*.234.87.2)
GigaDeath
자주 퀴즈를 내 주시는것도 좋을거 같군요. 스터디 하는 분들에게도 도움이 될듯. (바쁘시면 Pass~)
2003.07.16 14:58:42 (*.194.50.175)
baboneo
생각지도 않았던 곳에서 생성자나 소멸자가 호출되면 무척 당황스럽져~ ㅋㅋ
이런 예제를 볼 때마다 항상 궁금한건...
* 'foo'의 유래와 그 의미가 무엇일까? << 요거 요거~ -.-?
2003.07.16 15:30:18 (*.49.108.126)
neolith
그건 우리나라 프로그래머들이 생각없이 변수나 함수 이름 지을때 haha 나 hoho 를 쓰는 것과 마찬가지 아닐까요?
참고로 제가 아는 어떤 오래된 프로그래머는 임시로 변수 지을때마다 jaji 나 boji 같은 이름을 붙이곤 했었음 @_@
2003.07.16 17:13:19 (*.63.103.100)
브루펜시럽
변수명 짓느라 골치아플땐 우선 그렇게 해두면 되는 것이군요. >.<
2003.07.16 17:29:39 (*.72.178.65)
요플레
int i; 의 압박...
2003.07.16 18:22:36 (*.167.29.136)
snowflower
아무리그래도.. kekeke나.. f*ck 같은 이름은 좀.. -_-
2003.07.17 00:46:16 (*.72.135.148)
브루펜시럽
검은고래님 기억 안나시면 교제 314 페이지를 ~~
2003.07.17 01:17:17 (*.223.24.67)
baboneo
그렇겠죠? ㅋ
영상 처리에서 맨날 등장하는 Lena 아가씨(?)나...
3차원 그래픽에서 맨날 등장하는 Utah 주전자처럼...
학규님 주위에는 참 신비스러운 분들이 많네요~
소개시켜주세요~ +0+
2005.11.13 18:14:33 (*.144.160.247)
정희철
읔.. 실무에서 코딩을 배웠더니 기초 부족 >.< ;
2005.11.25 12:59:45 (*.144.160.245)
정희철
이 퀴즈 덕분에 c++의 전체 내용을 다시 한번 정리해볼 기회를 갖게 되었습니다. ^^
2005.11.25 13:11:36 (*.144.160.244)
정희철
저 같은 초짜 프로그래머를 위해 설명을 덧붙이겠습니다.
기본 복사 생성자가 호출되면 shallow copy(얕은 복사)가 일어납니다.
다시 말하면 what함수의 arg객체가 TestFixedlist함수의 b객체를 포인터로 참조 한다는 것입니다.
----
foo b(1);이 호출 될 때에 foo의 생성자 foo(int aa); 가 호출되면서 ctor이 출력됩니다.
what(b); 가 호출될 때 참조가 아닌 값의 전달이 일어나면서 복사 생성자가 호출됩니다. (b가 arg로 복사 될때) 복사 생성자가 없기 때문에 기본 복사 생성자가 호출됩니다.
what함수가 끝날 때 arg가 사라지므로 소멸자 호출
TestFixedlist가 호출될때 b가 사라지므로 소멸자 호출
그러므로 ctor은 한번 dtor은 두번 호출됩니다.
복사생성자를 추가하면 두번 호출되겠죠
foo(foo &f) { puts("ctor"); }