// explicit 없이 암시적인 변환을 막는다.(간접층 사용! proxy)
class Stack
{ 
        struct ploxy{
               int *buf;
               int top;
               proxy(int _sz):top(_sz),buf(new int[_sz])
               {
                       cout << "ploxy()" << endl;
               }
               ~proxy()
               {
                       cout << "~ploxy()" << endl;
                       delete buf;
               }
        };
        int * buf;
        int top;
public:
        Stack(proxy a):buf(a.buf),top(a.top)
        {
               cout << "Stack()" << endl;
        }
};
void foo(Stack s)
{
        cout << "foo()" << endl;
}
void main()
{
        Stack s(10); 
        foo(s);
        //foo(100); //error
}
class Stack
{
        int* buf;
        int top;
public:
        // 인자1개인생성자가암시적인변환의의미로사용되는것을막는다.
        // 단, 명시적변환은허용된다.
        explicit Stack( int sz = 10 ) {}
};
void foo( Stack s )
{
}
void main()
{
        Stack s;
        foo( s );
        foo( 100 );
         // 100 -> stack 이라면가능int->stack(변환생성자, 인자개인생성자!!
}
//////////////////////////////////////////////////////////////////////////
// 변환이야기.
void main()
{
        int n;
        cin >> n;      // 만약문자를입력하면실패한다.
        if( cin )
// cin.operaotr bool()로변환되면가능하다. cin은객체이지만if문안에들어갈수이유는???
// 실제로는cin.operator void*()로되어있다.
        {
               cout << "성공" << endl;
        }
}
class Point
{
        int x;
        int y;
public:
        // 인자가1개인생성자=> 변환생성자라고불린다.
        Point( int a ) : x(a), y(0) {}
        Point( int a = 0, int b = 0 ) : x(a), y(b) {}
// 변환연산자: Point 가int로변하게된다. 리턴값을표기하지않는다. 함수이름에리턴값있다.!!
        operator int()
        {
               return x;
        }
};
void main()
{
        Point p( 1, 2 );
        int n = 10;
        p = n;                 // int -> Point로변환되게한다. 변환생성자
        double d = 3.2;
        int n = d;
        Point p1( 1, 2 );
        int n2 = p1;   // ?Point -> int로변환p1.operator int() 가있으면된다.
}
