1. 핵심 개념
- fmt 라이브러리; Unreal에서는?
- if랑 switch 초기자
- switch [[fallthrough]]
- Short-circuit logic을 사용한 포인터검사
- C++20; <=> three-way comparison operator; strong_ordering, partial_ordering, weak_ordering; 다소 무거운 기존 비교 연산자를 두 번 호출할 필요 없음; compare 라이브러리 보기
- function prototype or function header vs function signature
- 1.1.35 타입추론 미리
- 함수 auto 리턴값 추론, auto랑 auto& 분석, __func__, 함수 오버로딩, 어트리뷰트 추가(nodiscard, maybe_unused, noreturn, deprecated, 20~ likely & unlikely)
0427 - C 스타일 배열은 {} 초기자 리스트시 원소 개수 배열 크기보다 적으면 자동 0; cpp에서는 std::array나 std:vector 사용 권장
- cpp는 CTAD(Class Template argument deduction) 기능 지원해서 초기자 사용 시 타입 추론
- std::pairt, std:optional
- 구조적 바인딩(structured binding)
- cpp20 범위 기반 for 문의 초기자
- initializer_list type-safe 함
- C 스타일 문자 배열: 스트링을 문자 배열로 표현, C++ 스타일 문자 배열: C 스타일로 표현된 스트링을 쉽ㅗ 안전하게 사용할 수 있도록 스트링 타입으로 감싼 방식
강의 - cpp Right-Left Rule
- NULL 포인터
- git lfs는 100mb가 넘어가는 파일 관리에 사용함 깃에는 파일의 정보만 넘기고 큰 용량의 파일은 lfs에서 저장함(용량 초과 시 유료 플랜)
git lfs install
git lfs tracked "*.png"
git add .gitattributes
git rm --cached test.txt // 기존 파일 lfs 등록을 위해 스테이징 영역에서 제거
git add test.text // lfs에 tracking2. 상세 내용
2. 상세 내용
2.1. [Right-Left Rule](C Right-Left Rule (Rick Ord's CSE 131 - UC San Diego))
C++에서의 연산자 우선순위를 사람이 읽기 좋게 정리한 규칙이다. 자세한 방법은 제목의 링크를 참고한다. (ps: &는 reference to, const는 constnat)
int *arr[5];
/*
-> []
arr is array of
<- *
arr is array of pointer to
-> nothing; <- int
arr is array of pointer to integer
*/
int (*p)[5];
/*
-> ()
p is
<- *
p is pointer to
-> []
p is pointer to array of
<- int
p is pointer to array of integer
*/
void (*fp)(int, double);
/*
fp is pointer to function expecting (int, double)
*/
int (*(*fp)(int))[5];
/*
fp is pointer to function expecting (int) and returning pointer to array(size 5) of integer
*/
void (*fp_arr[10])(int);
/*
fp_arr is array(size 10) of pointer to function expecting(int) and returning void
*/
int *& v;
/*
v is reference to pointer to integer
*/
const int * v; // int const * v;
/*
constant는 왼쪽(없다면 오른쪽)과 결합
v is pointer to constant integer
*/
int * const v;
/*
주의
v is constant pointer to integer
*/
const int * const & v;
/*
v is reference to constant pointer to constant interger
*/저 규칙으로 복잡한 자료형을 해석하는데 용이해졌지만 실제로는 코드 자체를 가독성 있게 작성하는 것이 바람직하다.
// int (*(*fp)(int))[5];
using IntArray5Ptr = int(*)[5];
using MyFunctionPtr = IntArray5Ptr (*)(int);
MyFinctionPtr fp; // int를 받아서 크기가 5인 int 배열 포인터를 반환2.2. NULL
[예전 게시글](NULL vs nullptr)에서 NULL vs nullptr에 대해서 정리한 적이 있다. 이번에는 거기서 추가로 알아낸 것을 정리해보려고 한다.
NULL은 C에서 #define NULL ((void*)0) 매크로와 동일하다.
// C 언어
int* p = NULL; // 실제로는 int* p = ((void*)0);이고 자동 형변환이 일어남(정상 작동)그러나 C++에서는 타입 안전성을 엄격하게 검사해서 #define NULL 0으로 강제 캐스팅 없이 매크로를 정의했다. 그러나 이 문제는 오버로딩에 문제를 일으켰고 이 문제를 막기 위해서 새롭게 nullptr이 등장했다.
#include <iostream>
void foo(int x) { std::cout << "int version called: " << x << std::endl; }
void foo(int* p) { std::cout << "pointer version called" << std::endl; }
int main() {
foo(0); // int version called: 0
foo(NULL); // int version called: 0(int 타입으로 해석됨)
foo(nullptr); // pointer version called (포인터 타입으로 해석됨)
}3. 질문 및 해결 (Q&A)
4. 관련 문서 (Links)
- [[이전 관련 노트]]
- 참고한 외부 링크
'내일배움캠프 > TIL' 카테고리의 다른 글
| TIL260429 - CPP (0) | 2026.04.29 |
|---|---|
| TIL260428 - Unreal (0) | 2026.04.28 |
| TIL260424 - CPP (0) | 2026.04.24 |
| TIL260423 (0) | 2026.04.23 |
| TIL260422 (0) | 2026.04.22 |