没什么可以多说的,看程序啦~~

#include <iostream>
#include 
<cstdlib>
using std::cout;
using std::endl;

class CObject;
typedef 
const CObject * LPCO;

class CObject
{
private:
    
int length;
    
int width;
    
int lefttop_xpoint;
    
int lefttop_ypoint;

public:
    CObject ( 
int l, int w, int x, int y );
    
operator LPCO ( ) const;
    
void co_print ( LPCO pco ) const;
}
;

CObject::CObject ( 
int l, int w, int x, int y )
{
    length 
= l ;
    width  
= w ;

    lefttop_xpoint 
= x ;
    lefttop_ypoint 
= y ;
}


CObject::
operator LPCO ( ) const
{
    
return (CObject *)(this) ;
}


void CObject::co_print ( LPCO pco ) const
{
    cout 
<< pco -> width          << endl
         
<< pco -> length         << endl
         
<< pco -> lefttop_xpoint << endl
         
<< pco -> lefttop_ypoint << endl ;
}


int main ()
{
    CObject co (
3456);
    co.co_print ( co ) ;

    system(
"pause");
}

只能说,灵活性是C/C++一脉相承的特性,安全隐患也是同样的一脉相承。
相对于其灵活性而言,我觉得,使用从对象到指针的自动转换,应当是不得已而为之的下策
posted on 2005-06-30 22:05  香依香偎孤旅独行的驿站  阅读(780)  评论(2编辑  收藏  举报