C & CPP
[CPP] using 과 typedef
에드윈H
2021. 11. 10. 10:38
둘은 크게 다르지 않지만, using의 장점은 template을 지원한다.
#include <iostream>
#include <vector>
template <typename T>
using my_vector = std::vector<T>;
using my_vector2 = std::vector<int>;
//vs
typedef std::vector<int> my_vector3;
//error!
//template <typename T>
//typedef std::vector<T> my_vector4;
int main()
{
//using
my_vector<int> a;
my_vector2 b;
//typedef
my_vector3 c;
return 0;
}
참고 :
https://unikys.tistory.com/381
[모던C++] typedef vs using 키워드 차이점
기존의 소스 코드에 쓰고 있는 forward declaration을 그대로 사용했더니 코드리뷰에서 typedef 를 쓰지 말라는 리뷰가 왔다. 그래서 찾아보니 모던C++에서는 이제 typedef 를 사용하지 않고 using 키워드를
unikys.tistory.com