usnig namespace MyNamespace;
스코프 내에서 네임스페이스에 정의된 모든 이름을 가져온다.
using std::cin
이런식으로 선택해서 가져올 수도 있다.
(C++11 이후) typedef처럼 type alias로 사용할 수 있다.
//typedef
typedef _int16 _windowlong;
typedef _int32 _linuxlong;
//using
using _windowlong = _int16;
using _linuxlong = _int32;
using 을 사용하면 템플릿 타입도 재정의할 수 있다.
template <typename T>
using vec = vector<T>;
상속관계에서 숨겨지는 맴버함수나 변수를 드러낸다.
class CObj
{
public:
void Invitation(int i)
{
cout << "hi" << endl;
}
};
class CDefived : CObj
{
public:
using CObj::Invitation;
void Invitation(string s)
{
cout << "Hello!" << endl;
}
};
참고로 같은 함수를 매개변수 바꾸면서 다른 스코프에서 정의하면 오버로딩이 아니라 그냥 덮어진다. 이걸 방지하고, 오버로딩 하기 위해 using 을 사용하는 것.