C++ 전역 함수의 이름과 클래스의 이름이 똑같을 경우..

loveistt의 이미지

예를 들어 Win32Api에서

Rectangle이라는 전역 함수가 있고요.

저는 똑같이 Rectangle이라는 이름을 가진 클래스를 만들었습니다.

제가 외부에서 (예를 들어 main이나..) b = new Rectangle();

이런식으로 부르면 위의 Rectangle이 전역함수로 처리되네요.

클래스 이름을 바꾸지 않고 해결할 수 있는 방법은 없을까요?

rasungboy의 이미지

네임스페이스를 쓰세요..

namespace test {

     class Rectangle {
      .....
     };
};

test::Rectangle* p = new test::Rectangle();
doldori의 이미지

namespace를 쓰세요.

void Rectangle();

namespace Mine
{
    class Rectangle { };
}

void f()
{
    using Mine::Rectangle;
    Rectangle* p = new Rectangle;
    ::Rectangle();  // function in global namespace
}