기본 콘텐츠로 건너뛰기

기본 생성자가 없는 객체 배열을 만들 수 있나?

C++ in Action Book: Pointers
There is no direct way to initialize the contents of a dynamically allocated array. We just have to iterate through the newly allocated array and set the values by hand.

C++에서 new연산자를 이용해서 객체배열을 만들 때, 객체에 기본생성자는 없고 다른 생성자가 있을 경우는 사용할 수 있는 문법 자체가 전무하다. 그냥 처음부터 끝까지 돌면서 하나하나 초기화 해주시라는 답안이다. 잇힝~*

C/C++이 상당히 유연하다고 생각했는데, 가끔씩 이런 것에서 뒷통수 때릴 수도 있다. 다른 언어는 어떨까? 왠지 Java/C#/D는 있을 것 같다.

댓글

이 블로그의 인기 게시물

탐색기에서 OneDrive 이 2개로 보이는 문제

왜 2개가 보이는지 모르겠지만, Registry 삭제하면 됨 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace 하위 키에서 OneDrive 둘 중에 하나만 지워도 바로 반영됨. 참조:  https://answers.microsoft.com/en-us/msoffice/forum/all/duplicate-onedrives-in-file-explorer/49c935a6-287b-43a5-aed5-2dee2a1c1b22