https://stackoverflow.com/questions/620137/do-the-parentheses-after-the-type-name-make-a-difference-with-new
[질문] by David Read
Test 가 보통 클래스라면, 아래 두가지에 차이가 있나?
Test* test = new Test;
Test* test = new Test();
[3번 답변] by bayda
일반적으로 첫번째 것은 디폴트-초기화, 두번째 것은 값-초기화가 된다.
예를 들어 int (POD 타입)의 경우
int* test = new int - *test의 값은 무엇이라도 될 수 있다.
int* test = new int() - *test 의 값은 0이 될 것이다.
이외의 동작은 Test 타입이 어떤 것인가에 달렸다. (이하생략)
[원문]
If 'Test' is an ordinary class, is there any difference between:
Test* test = new Test;
and
Test* test = new Test();
In general we have default-initialization in first case and value-initialization in second case.
For example: in case with int (POD type):
int* test = new int
- we have any initialization and value of *test can be any.int* test = new int()
- *test will have 0 value.
next behaviour depended from your type Test. We have defferent cases: Test have defult constructor, Test have generated default constructor, Test contain POD member, non POD member...
'프로그래밍 > C-CPP' 카테고리의 다른 글
[Win32] CharLowerA(utf8str) 은 문제가 생길 수 있다. (0) | 2018.08.29 |
---|---|
[VCPKG] VCPKG OFFLINE 사용하기 (0) | 2018.05.16 |
[CEF] CEF Chromium Embedded Framework 빌드하기 (0) | 2017.04.10 |
[VS2015] nuget package 오프라인 설치시 문제점. (4) | 2017.04.03 |
[VS] LINK : warning LNK4075: '/INCREMENTAL'이(가) '/LTCG' 사양으로 인해 무시됩니다. (0) | 2016.09.30 |