精华内容
下载资源
问答
  • C++类转换函数

    2019-02-26 10:56:44
    用转换构造函数可以将一个指定类型的数据转换为类的对象。但是不能反过来将一个类的对象转换为一个其他类型的数据(例如将一个Complex类...如果已声明了一个Complex类,可以Complex类中这样定义类型转换函数: ...

    用转换构造函数可以将一个指定类型的数据转换为类的对象。但是不能反过来将一个类的对象转换为一个其他类型的数据(例如将一个Complex类对象转换成double类型数据)。

    C++提供类型转换函数(type conversion function)来解决这个问题。类型转换函数的作用是将一个类的对象转换成另一类型的数据。如果已声明了一个Complex类,可以在Complex类中这样定义类型转换函数:

    operator double( )
    {
        return num;
    }

    函数返回double型变量num的值。它的作用是将一个Complex类对象转换为一个double型数据,其值是Complex类中的数据成员num的值。

    类型转换函数的一般形式为:
     

        operator 类型名( )
        {
            实现转换的语句
        }

    在函数名前面不能指定函数类型,函数没有参数。其返回值的类型是由函数名中指定的类型名来确定的。类型转换函数只能作为成员函数,因为转换的主体是本类的对象。不能作为友元函数或普通函数。

    从函数形式可以看到,它与运算符重载函数相似,都是用关键字operator开头,只是被重载的是类型名。double类型经过重载后,除了原有的含义外,还获得新的含义(将一个Complex类对象转换为double类型数据,并指定了转换方法)。这样,编译系统不仅能识别原有的double型数据,而且还会把Complex类对象作为double型数据处理。

    那么程序中的Complex类对具有双重身份,既是Complex类对象,又可作为double类型数据。Complex类对象只有在需要时才进行转换,要根据表达式的上下文来决定。转换构造函数和类型转换运算符有一个共同的功能:当需要的时候,编译系统会自动调用这些函数,建立一个无名的临时对象(或临时变量)。

    展开全文
  • 转换函数

    2013-06-17 21:41:13
    在类通过指定关键字operator,并在其后加上转换的目标类型后,我们就可以声明转换函数。转换函数采用如下的一般形式: operator type() ;  这里的type可用内置类型,类类型或typedef名取代。但是不允许表示数组...

          转换函数是一种特殊类型的类成员函数。它定义了一个由用户定义的转换,以便把一个类对象转换成某种其他的类型。在类体中通过指定关键字operator,并在其后加上转换的目标类型后,我们就可以声明转换函数。转换函数采用如下的一般形式:

    operator type() ;

          这里的type可用内置类型,类类型或typedef名取代。但是不允许表示数组或函数类型。转换函数必须是成员函数,它的声明不能指定返回类型和参数表。例如,以下声明都是错误的:

    operator int(SmallInt&) ;   //错误:不是成员函数
    
    class SmallInt
    {
    public:
    	int operator int() ; // 错误:指定了返回类型
    	operator int(int = 0) ; //错误:指定了参数表
    	
    	operator int () ;  //正确
    };
    

    http://qq.100bt.com/topic-12122897-1.html
    具体可以看下面的一个例子来理解下转换函数。

    class SmallInt
    {
    public:
    	SmallInt(int ival) : value(ival) { } 
    
    	//转换操作符  SmallInt ==> int
    	operator int () {return value};  
    private:
    	int value ;
    };
    
    SmallInt si(3) ;
    si + 3.1415 ;

           在本例中,指定的类型是int。转换函数定义了转换的意义以及应用转换时编译器必须执行的动作。从SmallInt类对象到int型转换的意义是:返回存储在数据成员value中的int型的值。

           我们再看程序的最后两句:

    SmallInt si(3) ;
    si + 3.1415 ;


    可以被解析为如下两步:

    1、调用SmallInt转换函数,产生整型值3

    2、整型值3被提升为3.0,并与double文字常量3.1415相加,生成double型6.1415。

     

           最后,还有一点需注意:构造函数也可以作为转换函数。在一个类的构造函数中,凡是只带一个参数的构造函数,例如SmaiiInt的构造函数SmallInt(int)。都定义了一组隐式转换,把构造函数的参数类型转换为该类的类型。例如,SmallInt(int)把int型的值转换成SmallInt值:

    extern void calc(SmallInt) ;
    int i ;
    //需要把i转换成一个SmallInt值
    //SmallInt(int)可以做到这一点
    calc(i) ;

          在调用calc(i)中,通过调用构造函数SmallInt(int)把i转换成SmallInt类型的值。编译器调用构造函数创建一个SmallInt类型的临时对象。然后,再将这个对象的值的拷贝传递给calc()。可以将上述函数的调用理解成这样:

    //C++伪代码
    //创建一个临时对象
    {
    	SmallInt temp = SmallInt(i) ;
    	calc(temp) ; //按值传递,所以讲temp的拷贝传给calc的参数 
    }
    /*
    上面例子的花括号指出了SmallInt的临时对象的生命期,即,临时对象会在函数调用语句结束时被销毁
    */


     


     




























































    http://www.hxtk.com/html/55/55458/.shtml
    http://www.hxtk.com/html/55/55458/1463141.shtml
    http://www.hxtk.com/html/55/55458/1463159.shtml
    http://www.hxtk.com/html/55/55458/1463172.shtml
    http://www.hxtk.com/html/55/55458/1463183.shtml
    http://www.hxtk.com/html/55/55458/1468575.shtml
    http://www.hxtk.com/html/55/55458/1468582.shtml
    http://www.hxtk.com/html/55/55458/1468584.shtml
    http://www.hxtk.com/html/55/55458/1468586.shtml
    http://www.hxtk.com/html/55/55458/1468604.shtml
    http://www.hxtk.com/html/55/55458/1468611.shtml
    http://www.hxtk.com/html/55/55458/1468614.shtml
    http://www.hxtk.com/html/55/55458/1468623.shtml
    http://www.hxtk.com/html/55/55458/1468625.shtml
    http://www.hxtk.com/html/55/55458/1468628.shtml
    http://www.hxtk.com/html/55/55458/1468633.shtml
    http://www.hxtk.com/html/55/55458/1468638.shtml
    http://www.hxtk.com/html/55/55458/1468641.shtml
    http://www.hxtk.com/html/55/55458/1468644.shtml
    http://www.hxtk.com/html/55/55458/1468648.shtml
    http://www.hxtk.com/html/55/55458/1468656.shtml
    http://www.hxtk.com/html/55/55458/1468657.shtml
    http://www.hxtk.com/html/55/55458/1468661.shtml
    http://www.hxtk.com/html/55/55458/1468666.shtml
    http://www.hxtk.com/html/55/55458/1468669.shtml
    http://www.hxtk.com/html/55/55458/1468673.shtml
    http://www.hxtk.com/html/55/55458/1468678.shtml
    http://www.hxtk.com/html/55/55458/1468680.shtml
    http://www.hxtk.com/html/55/55458/1468682.shtml
    http://www.hxtk.com/html/55/55458/1468685.shtml
    http://www.hxtk.com/html/55/55458/1468688.shtml
    http://www.hxtk.com/html/55/55458/1468695.shtml
    http://www.hxtk.com/html/55/55458/1468697.shtml
    http://www.hxtk.com/html/55/55458/1468700.shtml
    http://www.hxtk.com/html/55/55458/1468704.shtml
    http://www.hxtk.com/html/55/55458/1468708.shtml
    http://www.hxtk.com/html/55/55458/1468713.shtml
    http://www.hxtk.com/html/55/55458/1468724.shtml
    http://www.hxtk.com/html/55/55458/1468739.shtml
    http://www.hxtk.com/html/55/55458/1468746.shtml
    http://www.hxtk.com/html/55/55458/1468752.shtml
    http://www.hxtk.com/html/55/55458/1468754.shtml
    http://www.hxtk.com/html/55/55458/1468756.shtml
    http://www.hxtk.com/html/55/55458/1468760.shtml
    http://www.hxtk.com/html/55/55458/1468761.shtml
    http://www.hxtk.com/html/55/55458/1468762.shtml
    http://www.hxtk.com/html/55/55458/1468766.shtml
    http://www.hxtk.com/html/55/55458/1468767.shtml
    http://www.hxtk.com/html/55/55458/1468770.shtml
    http://www.hxtk.com/html/55/55458/1468772.shtml
    http://www.hxtk.com/html/55/55458/1468774.shtml
    http://www.hxtk.com/html/55/55458/1468776.shtml
    http://www.hxtk.com/html/55/55458/1468780.shtml
    http://www.hxtk.com/html/55/55458/1468781.shtml
    http://www.hxtk.com/html/55/55458/1468783.shtml
    http://www.hxtk.com/html/55/55458/1468786.shtml
    http://www.hxtk.com/html/55/55458/1468789.shtml
    http://www.hxtk.com/html/55/55458/1468793.shtml
    http://www.hxtk.com/html/55/55458/1468798.shtml
    http://www.hxtk.com/html/55/55458/1468803.shtml
    http://www.hxtk.com/html/55/55458/1468807.shtml
    http://www.hxtk.com/html/55/55458/1468820.shtml
    http://www.hxtk.com/html/55/55458/1468826.shtml
    http://www.hxtk.com/html/55/55458/1468845.shtml
    http://www.hxtk.com/html/55/55458/1468849.shtml
    http://www.hxtk.com/html/55/55458/1468858.shtml
    http://www.hxtk.com/html/55/55458/1468859.shtml
    http://www.hxtk.com/html/55/55458/1468864.shtml
    http://www.hxtk.com/html/55/55458/1468866.shtml
    http://www.hxtk.com/html/55/55458/1468870.shtml
    http://www.hxtk.com/html/55/55458/1468873.shtml
    http://www.hxtk.com/html/55/55458/1468874.shtml
    http://www.hxtk.com/html/55/55458/1468880.shtml
    http://www.hxtk.com/html/55/55458/1468883.shtml
    http://www.hxtk.com/html/55/55458/1468892.shtml
    http://www.hxtk.com/html/55/55458/1468895.shtml
    http://www.hxtk.com/html/55/55458/1468901.shtml
    http://www.hxtk.com/html/55/55458/1468905.shtml
    http://www.hxtk.com/html/55/55458/1468914.shtml
    http://www.hxtk.com/html/55/55458/1468918.shtml
    http://www.hxtk.com/html/55/55458/1468930.shtml
    http://www.hxtk.com/html/55/55458/1468965.shtml
    http://www.hxtk.com/html/55/55458/1468977.shtml
    http://www.hxtk.com/html/55/55458/1468980.shtml
    http://www.hxtk.com/html/55/55458/1468990.shtml
    http://www.hxtk.com/html/55/55458/1468992.shtml
    http://www.hxtk.com/html/55/55458/1468998.shtml
    http://www.hxtk.com/html/55/55458/1469002.shtml
    http://www.hxtk.com/html/55/55458/1469011.shtml
    http://www.hxtk.com/html/55/55458/1469015.shtml
    http://www.hxtk.com/html/55/55458/1469021.shtml
    http://www.hxtk.com/html/55/55458/1469023.shtml
    http://www.hxtk.com/html/55/55458/1469029.shtml
    http://www.hxtk.com/html/55/55458/1469033.shtml
    http://www.hxtk.com/html/55/55458/1469039.shtml
    http://www.hxtk.com/html/55/55458/1469041.shtml
    http://www.hxtk.com/html/55/55458/1469048.shtml
    http://www.hxtk.com/html/55/55458/1469052.shtml
    http://www.hxtk.com/html/55/55458/1469060.shtml
    http://www.hxtk.com/html/55/55458/1469063.shtml
    http://www.hxtk.com/html/55/55458/1469068.shtml
    http://www.hxtk.com/html/55/55458/1469073.shtml
    http://www.hxtk.com/html/55/55458/1469078.shtml
    http://www.hxtk.com/html/55/55458/1469082.shtml
    http://www.hxtk.com/html/55/55458/1469087.shtml
    http://www.hxtk.com/html/55/55458/1469090.shtml
    http://www.hxtk.com/html/55/55458/1469094.shtml
    http://www.hxtk.com/html/55/55458/1469097.shtml
    http://www.hxtk.com/html/55/55458/1469103.shtml
    http://www.hxtk.com/html/55/55458/1469108.shtml
    http://www.hxtk.com/html/55/55458/1469120.shtml
    http://www.hxtk.com/html/55/55458/1469132.shtml
    http://www.hxtk.com/html/55/55458/1469196.shtml
    http://www.hxtk.com/html/55/55458/1469213.shtml
    http://www.hxtk.com/html/55/55458/1469226.shtml
    http://www.hxtk.com/html/55/55458/1469235.shtml
    http://www.hxtk.com/html/55/55458/1469257.shtml
    http://www.hxtk.com/html/55/55458/1469261.shtml
    http://www.hxtk.com/html/55/55458/1469291.shtml
    http://www.hxtk.com/html/55/55458/1469332.shtml
    http://www.hxtk.com/html/55/55458/1469337.shtml
    http://www.hxtk.com/html/55/55458/1469345.shtml
    http://www.hxtk.com/html/55/55458/1469355.shtml
    http://www.hxtk.com/html/55/55458/1469375.shtml
    http://www.hxtk.com/html/55/55458/1469386.shtml
    http://www.hxtk.com/html/55/55458/1469397.shtml
    http://www.hxtk.com/html/55/55458/1469415.shtml
    http://www.hxtk.com/html/55/55458/1469429.shtml
    http://www.hxtk.com/html/55/55458/1469442.shtml
    http://www.hxtk.com/html/55/55458/1469457.shtml
    http://www.hxtk.com/html/55/55458/1469472.shtml
    http://www.hxtk.com/html/55/55458/1469487.shtml
    http://www.hxtk.com/html/55/55458/1469505.shtml
    http://www.hxtk.com/html/55/55458/1469520.shtml
    http://www.hxtk.com/html/55/55458/1469526.shtml
    http://www.hxtk.com/html/55/55458/1469537.shtml
    http://www.hxtk.com/html/55/55458/1469547.shtml
    http://www.hxtk.com/html/55/55458/1469560.shtml
    http://www.hxtk.com/html/55/55458/1469566.shtml
    http://www.hxtk.com/html/55/55458/1469620.shtml
    http://www.hxtk.com/html/55/55458/1469624.shtml
    http://www.hxtk.com/html/55/55458/1469630.shtml
    http://www.hxtk.com/html/55/55458/1469637.shtml
    http://www.hxtk.com/html/55/55458/1469645.shtml
    http://www.hxtk.com/html/55/55458/1470013.shtml
    http://www.hxtk.com/html/55/55458/1470014.shtml
    http://www.hxtk.com/html/55/55458/1470049.shtml
    http://www.hxtk.com/html/55/55458/1470061.shtml
    http://www.hxtk.com/html/55/55458/1470077.shtml
    http://www.hxtk.com/html/55/55458/1470092.shtml
    http://www.hxtk.com/html/55/55458/1470115.shtml
    http://www.hxtk.com/html/55/55458/1470150.shtml
    http://www.hxtk.com/html/55/55458/1470157.shtml
    http://www.hxtk.com/html/55/55458/1470168.shtml
    http://www.hxtk.com/html/55/55458/1470182.shtml
    http://www.hxtk.com/html/55/55458/1470192.shtml
    http://www.hxtk.com/html/55/55458/1470201.shtml
    http://www.hxtk.com/html/55/55458/1470210.shtml
    http://www.hxtk.com/html/55/55458/1470221.shtml
    http://www.hxtk.com/html/55/55458/1470228.shtml
    http://www.hxtk.com/html/55/55458/1470243.shtml
    http://www.hxtk.com/html/55/55458/1470256.shtml
    http://www.hxtk.com/html/55/55458/1470274.shtml
    http://www.hxtk.com/html/55/55458/1470284.shtml
    http://www.hxtk.com/html/55/55458/1470301.shtml
    http://www.hxtk.com/html/55/55458/1470408.shtml
    http://www.hxtk.com/html/55/55458/1470425.shtml
    http://www.hxtk.com/html/55/55458/1470442.shtml
    http://www.hxtk.com/html/55/55458/1470489.shtml
    http://www.hxtk.com/html/55/55458/1470517.shtml
    http://www.hxtk.com/html/55/55458/1470520.shtml
    http://www.hxtk.com/html/55/55458/1470525.shtml
    http://www.hxtk.com/html/55/55458/1470529.shtml
    http://www.hxtk.com/html/55/55458/1470533.shtml
    http://www.hxtk.com/html/55/55458/1470540.shtml
    http://www.hxtk.com/html/55/55458/1470556.shtml
    http://www.hxtk.com/html/55/55458/1470565.shtml
    http://www.hxtk.com/html/55/55458/1470570.shtml
    http://www.hxtk.com/html/55/55458/1470571.shtml
    http://www.hxtk.com/html/55/55458/1470575.shtml
    http://www.hxtk.com/html/55/55458/1470578.shtml
    http://www.hxtk.com/html/55/55458/1470581.shtml
    http://www.hxtk.com/html/55/55458/1470588.shtml
    http://www.hxtk.com/html/55/55458/1470592.shtml
    http://www.hxtk.com/html/55/55458/1470597.shtml
    http://www.hxtk.com/html/55/55458/1470599.shtml
    http://www.hxtk.com/html/55/55458/1470604.shtml
    http://www.hxtk.com/html/55/55458/1470607.shtml
    http://www.hxtk.com/html/55/55458/1470609.shtml
    http://www.hxtk.com/html/55/55458/1470613.shtml
    http://www.hxtk.com/html/55/55458/1470617.shtml
    http://www.hxtk.com/html/55/55458/1470623.shtml
    http://www.hxtk.com/html/55/55458/1470630.shtml
    http://www.hxtk.com/html/55/55458/1470635.shtml
    http://www.hxtk.com/html/55/55458/1470640.shtml
    http://www.hxtk.com/html/55/55458/1470643.shtml
    http://www.hxtk.com/html/55/55458/1470652.shtml
    http://www.hxtk.com/html/55/55458/1470659.shtml
    http://www.hxtk.com/html/55/55458/1470663.shtml
    http://www.hxtk.com/html/55/55458/1470666.shtml
    http://www.hxtk.com/html/55/55458/1470671.shtml
    http://www.hxtk.com/html/55/55458/1470677.shtml
    http://www.hxtk.com/html/55/55458/1470685.shtml
    http://www.hxtk.com/html/55/55458/1470692.shtml
    http://www.hxtk.com/html/55/55458/1470697.shtml
    http://www.hxtk.com/html/55/55458/1470703.shtml
    http://www.hxtk.com/html/55/55458/1470708.shtml
    http://www.hxtk.com/html/55/55458/1470710.shtml
    http://www.hxtk.com/html/55/55458/1470716.shtml
    http://www.hxtk.com/html/55/55458/1470724.shtml
    http://www.hxtk.com/html/55/55458/1470728.shtml
    http://www.hxtk.com/html/55/55458/1470734.shtml
    http://www.hxtk.com/html/55/55458/1470742.shtml
    http://www.hxtk.com/html/55/55458/1470750.shtml
    http://www.hxtk.com/html/55/55458/1470755.shtml
    http://www.hxtk.com/html/55/55458/1470762.shtml
    http://www.hxtk.com/html/55/55458/1470805.shtml
    http://www.hxtk.com/html/55/55458/1470811.shtml
    http://www.hxtk.com/html/55/55458/1470817.shtml
    http://www.hxtk.com/html/55/55458/1470823.shtml
    http://www.hxtk.com/html/55/55458/1470830.shtml
    http://www.hxtk.com/html/55/55458/1470840.shtml
    http://www.hxtk.com/html/55/55458/1470847.shtml
    http://www.hxtk.com/html/55/55458/1470853.shtml
    http://www.hxtk.com/html/55/55458/1470858.shtml
    http://www.hxtk.com/html/55/55458/1470861.shtml
    http://www.hxtk.com/html/55/55458/1470867.shtml
    http://www.hxtk.com/html/55/55458/1470876.shtml
    http://www.hxtk.com/html/55/55458/1470889.shtml
    http://www.hxtk.com/html/55/55458/1470925.shtml
    http://www.hxtk.com/html/55/55458/1470942.shtml
    http://www.hxtk.com/html/55/55458/1470953.shtml
    http://www.hxtk.com/html/55/55458/1470966.shtml
    http://www.hxtk.com/html/55/55458/1470979.shtml
    http://www.hxtk.com/html/55/55458/1470987.shtml
    http://www.hxtk.com/html/55/55458/1471001.shtml
    http://www.hxtk.com/html/55/55458/1471025.shtml
    http://www.hxtk.com/html/55/55458/1471032.shtml
    http://www.hxtk.com/html/55/55458/1471040.shtml
    http://www.hxtk.com/html/55/55458/1471056.shtml
    http://www.hxtk.com/html/55/55458/1471060.shtml
    http://www.hxtk.com/html/55/55458/1471063.shtml
    http://www.hxtk.com/html/55/55458/1471067.shtml
    http://www.hxtk.com/html/55/55458/1471072.shtml
    http://www.hxtk.com/html/55/55458/1471081.shtml
    http://www.hxtk.com/html/55/55458/1471090.shtml
    http://www.hxtk.com/html/55/55458/1471097.shtml
    http://www.hxtk.com/html/55/55458/1471102.shtml
    http://www.hxtk.com/html/55/55458/1471110.shtml
    http://www.hxtk.com/html/55/55458/1471121.shtml
    http://www.hxtk.com/html/55/55458/1471141.shtml
    http://www.hxtk.com/html/55/55458/1471155.shtml
    http://www.hxtk.com/html/55/55458/1471173.shtml
    http://www.hxtk.com/html/55/55458/1471194.shtml
    http://www.hxtk.com/html/55/55458/1471209.shtml
    http://www.hxtk.com/html/55/55458/1471220.shtml
    http://www.hxtk.com/html/55/55458/1471236.shtml
    http://www.hxtk.com/html/55/55458/1471249.shtml
    http://www.hxtk.com/html/55/55458/1471262.shtml
    http://www.hxtk.com/html/55/55458/1471274.shtml
    http://www.hxtk.com/html/55/55458/1471290.shtml
    http://www.hxtk.com/html/55/55458/1471305.shtml
    http://www.hxtk.com/html/55/55458/1471316.shtml
    http://www.hxtk.com/html/55/55458/1471334.shtml
    http://www.hxtk.com/html/55/55458/1471347.shtml
    http://www.hxtk.com/html/55/55458/1471407.shtml
    http://www.hxtk.com/html/55/55458/1471434.shtml
    http://www.hxtk.com/html/55/55458/1471457.shtml
    http://www.hxtk.com/html/55/55458/1471475.shtml
    http://www.hxtk.com/html/55/55458/1471483.shtml
    http://www.hxtk.com/html/55/55458/1471495.shtml
    http://www.hxtk.com/html/55/55458/1471508.shtml
    http://www.hxtk.com/html/55/55458/1471516.shtml
    http://www.hxtk.com/html/55/55458/1471525.shtml
    http://www.hxtk.com/html/55/55458/1471536.shtml
    http://www.hxtk.com/html/55/55458/1471549.shtml
    http://www.hxtk.com/html/55/55458/1471585.shtml
    http://www.hxtk.com/html/55/55458/1471618.shtml
    http://www.hxtk.com/html/55/55458/1471622.shtml
    http://www.hxtk.com/html/55/55458/1471645.shtml
    http://www.hxtk.com/html/55/55458/1471676.shtml
    http://www.hxtk.com/html/55/55458/1471686.shtml
    http://www.hxtk.com/html/55/55458/1471693.shtml
    http://www.hxtk.com/html/55/55458/1471701.shtml
    http://www.hxtk.com/html/55/55458/1471707.shtml
    http://www.hxtk.com/html/55/55458/1471712.shtml
    http://www.hxtk.com/html/55/55458/1471716.shtml
    http://www.hxtk.com/html/55/55458/1471720.shtml
    http://www.hxtk.com/html/55/55458/1471731.shtml
    http://www.hxtk.com/html/55/55458/1471732.shtml
    http://www.hxtk.com/html/55/55458/1471742.shtml
    http://www.hxtk.com/html/55/55458/1471743.shtml
    http://www.hxtk.com/html/55/55458/1471751.shtml
    http://www.hxtk.com/html/55/55458/1471752.shtml
    http://www.hxtk.com/html/55/55458/1471764.shtml
    http://www.hxtk.com/html/55/55458/1471766.shtml
    http://www.hxtk.com/html/55/55458/1471773.shtml
    http://www.hxtk.com/html/55/55458/1471778.shtml
    http://www.hxtk.com/html/55/55458/1471783.shtml
    http://www.hxtk.com/html/55/55458/1471787.shtml
    http://www.hxtk.com/html/55/55458/1471794.shtml
    http://www.hxtk.com/html/55/55458/1471799.shtml
    http://www.hxtk.com/html/55/55458/1471804.shtml
    http://www.hxtk.com/html/55/55458/1471814.shtml
    http://www.hxtk.com/html/55/55458/1471819.shtml
    http://www.hxtk.com/html/55/55458/1471826.shtml
    http://www.hxtk.com/html/55/55458/1471830.shtml
    http://www.hxtk.com/html/55/55458/1471837.shtml
    http://www.hxtk.com/html/55/55458/1471842.shtml
    http://www.hxtk.com/html/55/55458/1471848.shtml
    http://www.hxtk.com/html/55/55458/1471851.shtml
    http://www.hxtk.com/html/55/55458/1471857.shtml
    http://www.hxtk.com/html/55/55458/1471861.shtml
    http://www.hxtk.com/html/55/55458/1471870.shtml
    http://www.hxtk.com/html/55/55458/1471877.shtml
    http://www.hxtk.com/html/55/55458/1471880.shtml
    http://www.hxtk.com/html/55/55458/1471883.shtml
    http://www.hxtk.com/html/55/55458/1471887.shtml
    http://www.hxtk.com/html/55/55458/1471892.shtml
    http://www.hxtk.com/html/55/55458/1471894.shtml
    http://www.hxtk.com/html/55/55458/1471901.shtml
    http://www.hxtk.com/html/55/55458/1471903.shtml
    http://www.hxtk.com/html/55/55458/1471907.shtml
    http://www.hxtk.com/html/55/55458/1471912.shtml
    http://www.hxtk.com/html/55/55458/1471917.shtml
    http://www.hxtk.com/html/55/55458/1471919.shtml
    http://www.hxtk.com/html/55/55458/1471924.shtml
    http://www.hxtk.com/html/55/55458/1471927.shtml
    http://www.hxtk.com/html/55/55458/1471935.shtml
    http://www.hxtk.com/html/55/55458/1471938.shtml
    http://www.hxtk.com/html/55/55458/1471943.shtml
    http://www.hxtk.com/html/55/55458/1471946.shtml
    http://www.hxtk.com/html/55/55458/1471952.shtml
    http://www.hxtk.com/html/55/55458/1471957.shtml
    http://www.hxtk.com/html/55/55458/1471962.shtml
    http://www.hxtk.com/html/55/55458/1471965.shtml
    http://www.hxtk.com/html/55/55458/1471973.shtml
    http://www.hxtk.com/html/55/55458/1471977.shtml
    http://www.hxtk.com/html/55/55458/1471981.shtml
    http://www.hxtk.com/html/55/55458/1471992.shtml
    http://www.hxtk.com/html/55/55458/1471995.shtml
    http://www.hxtk.com/html/55/55458/1472004.shtml
    http://www.hxtk.com/html/55/55458/1472005.shtml
    http://www.hxtk.com/html/55/55458/1472014.shtml
    http://www.hxtk.com/html/55/55458/1472015.shtml
    http://www.hxtk.com/html/55/55458/1472031.shtml
    http://www.hxtk.com/html/55/55458/1472040.shtml
    http://www.hxtk.com/html/55/55458/1472046.shtml
    http://www.hxtk.com/html/55/55458/1472050.shtml
    http://www.hxtk.com/html/55/55458/1472056.shtml
    http://www.hxtk.com/html/55/55458/1472077.shtml
    http://www.hxtk.com/html/55/55458/1472086.shtml
    http://www.hxtk.com/html/55/55458/1472087.shtml
    http://www.hxtk.com/html/55/55458/1472096.shtml
    http://www.hxtk.com/html/55/55458/1472098.shtml
    http://www.hxtk.com/html/55/55458/1472103.shtml
    http://www.hxtk.com/html/55/55458/1472106.shtml
    http://www.hxtk.com/html/55/55458/1472112.shtml
    http://www.hxtk.com/html/55/55458/1472114.shtml
    http://www.hxtk.com/html/55/55458/1472118.shtml
    http://www.hxtk.com/html/55/55458/1472122.shtml
    http://www.hxtk.com/html/55/55458/1472125.shtml
    http://www.hxtk.com/html/55/55458/1472129.shtml
    http://www.hxtk.com/html/55/55458/1472134.shtml
    http://www.hxtk.com/html/55/55458/1472144.shtml
    http://www.hxtk.com/html/55/55458/1472157.shtml
    http://www.hxtk.com/html/55/55458/1472160.shtml
    http://www.hxtk.com/html/55/55458/1472174.shtml
    http://www.hxtk.com/html/55/55458/1472184.shtml
    http://www.hxtk.com/html/55/55458/1472187.shtml
    http://www.hxtk.com/html/55/55458/1472207.shtml
    http://www.hxtk.com/html/55/55458/1472212.shtml
    http://www.hxtk.com/html/55/55458/1472218.shtml
    http://www.hxtk.com/html/55/55458/1472224.shtml
    http://www.hxtk.com/html/55/55458/1472230.shtml
    http://www.hxtk.com/html/55/55458/1472248.shtml
    http://www.hxtk.com/html/55/55458/1472257.shtml
    http://www.hxtk.com/html/55/55458/1472262.shtml
    http://www.hxtk.com/html/55/55458/1472274.shtml
    http://www.hxtk.com/html/55/55458/1472287.shtml
    http://www.hxtk.com/html/55/55458/1472288.shtml
    http://www.hxtk.com/html/55/55458/1472308.shtml
    http://www.hxtk.com/html/55/55458/1472337.shtml
    http://www.hxtk.com/html/55/55458/1472355.shtml
    http://www.hxtk.com/html/55/55458/1472380.shtml
    http://www.hxtk.com/html/55/55458/1472391.shtml
    http://www.hxtk.com/html/55/55458/1472421.shtml
    http://www.hxtk.com/html/55/55458/1472434.shtml
    http://www.hxtk.com/html/55/55458/1472467.shtml
    http://www.hxtk.com/html/55/55458/1472500.shtml
    http://www.hxtk.com/html/55/55458/1472519.shtml
    http://www.hxtk.com/html/55/55458/1472535.shtml
    http://www.hxtk.com/html/55/55458/1472552.shtml
    http://www.hxtk.com/html/55/55458/1472562.shtml
    http://www.hxtk.com/html/55/55458/1472603.shtml
    http://www.hxtk.com/html/55/55458/1472613.shtml
    http://www.hxtk.com/html/55/55458/1472634.shtml
    http://www.hxtk.com/html/55/55458/1472635.shtml
    http://www.hxtk.com/html/55/55458/1472649.shtml
    http://www.hxtk.com/html/55/55458/1472663.shtml
    http://www.hxtk.com/html/55/55458/1472677.shtml
    http://www.hxtk.com/html/55/55458/1472691.shtml
    http://www.hxtk.com/html/55/55458/1472695.shtml
    http://www.hxtk.com/html/55/55458/1472702.shtml
    http://www.hxtk.com/html/55/55458/1472708.shtml
    http://www.hxtk.com/html/55/55458/1472730.shtml
    http://www.hxtk.com/html/55/55458/1472735.shtml
    http://www.hxtk.com/html/55/55458/1472747.shtml
    http://www.hxtk.com/html/55/55458/1472758.shtml
    http://www.hxtk.com/html/55/55458/1472770.shtml
    http://www.hxtk.com/html/55/55458/1472777.shtml
    http://www.hxtk.com/html/55/55458/1472795.shtml
    http://www.hxtk.com/html/55/55458/1472805.shtml
    http://www.hxtk.com/html/55/55458/1472820.shtml
    http://www.hxtk.com/html/55/55458/1472832.shtml
    http://www.hxtk.com/html/55/55458/1472841.shtml
    http://www.hxtk.com/html/55/55458/1472848.shtml
    http://www.hxtk.com/html/55/55458/1472849.shtml
    http://www.hxtk.com/html/55/55458/1472862.shtml
    http://www.hxtk.com/html/55/55458/1472865.shtml
    http://www.hxtk.com/html/55/55458/1472880.shtml
    http://www.hxtk.com/html/55/55458/1472881.shtml
    http://www.hxtk.com/html/55/55458/1472888.shtml
    http://www.hxtk.com/html/55/55458/1472898.shtml
    http://www.hxtk.com/html/55/55458/1472905.shtml
    http://www.hxtk.com/html/55/55458/1472906.shtml
    http://www.hxtk.com/html/55/55458/1472917.shtml
    http://www.hxtk.com/html/55/55458/1472921.shtml
    http://www.hxtk.com/html/55/55458/1472927.shtml
    http://www.hxtk.com/html/55/55458/1472937.shtml
    http://www.hxtk.com/html/55/55458/1472941.shtml
    http://www.hxtk.com/html/55/55458/1472957.shtml
    http://www.hxtk.com/html/55/55458/1472958.shtml
    http://www.hxtk.com/html/55/55458/1472975.shtml
    http://www.hxtk.com/html/55/55458/1472976.shtml
    http://www.hxtk.com/html/55/55458/1472988.shtml
    http://www.hxtk.com/html/55/55458/1472989.shtml
    http://www.hxtk.com/html/55/55458/1472993.shtml
    http://www.hxtk.com/html/55/55458/1473001.shtml
    http://www.hxtk.com/html/55/55458/1473006.shtml
    http://www.hxtk.com/html/55/55458/1473013.shtml
    http://www.hxtk.com/html/55/55458/1473022.shtml
    http://www.hxtk.com/html/55/55458/1473030.shtml
    http://www.hxtk.com/html/55/55458/1473031.shtml
    http://www.hxtk.com/html/55/55458/1473041.shtml
    http://www.hxtk.com/html/55/55458/1473049.shtml
    http://www.hxtk.com/html/55/55458/1473050.shtml
    http://www.hxtk.com/html/55/55458/1473066.shtml
    http://www.hxtk.com/html/55/55458/1473068.shtml
    http://www.hxtk.com/html/55/55458/1473084.shtml
    http://www.hxtk.com/html/55/55458/1473091.shtml
    http://www.hxtk.com/html/55/55458/1473098.shtml
    http://www.hxtk.com/html/55/55458/1473108.shtml
    http://www.hxtk.com/html/55/55458/1473109.shtml
    http://www.hxtk.com/html/55/55458/1473118.shtml
    http://www.hxtk.com/html/55/55458/1473126.shtml
    http://www.hxtk.com/html/55/55458/1473128.shtml
    http://www.hxtk.com/html/55/55458/1473140.shtml
    http://www.hxtk.com/html/55/55458/1473145.shtml
    http://www.hxtk.com/html/55/55458/1473154.shtml
    http://www.hxtk.com/html/55/55458/1473156.shtml
    http://www.hxtk.com/html/55/55458/1473171.shtml
    http://www.hxtk.com/html/55/55458/1473177.shtml
    http://www.hxtk.com/html/55/55458/1473185.shtml
    http://www.hxtk.com/html/55/55458/1473195.shtml
    http://www.hxtk.com/html/55/55458/1473196.shtml
    http://www.hxtk.com/html/55/55458/1473213.shtml
    http://www.hxtk.com/html/55/55458/1473222.shtml
    http://www.hxtk.com/html/55/55458/1473223.shtml
    http://www.hxtk.com/html/55/55458/1473235.shtml
    http://www.hxtk.com/html/55/55458/1473241.shtml
    http://www.hxtk.com/html/55/55458/1473248.shtml
    http://www.hxtk.com/html/55/55458/1473255.shtml
    http://www.hxtk.com/html/55/55458/1473265.shtml
    http://www.hxtk.com/html/55/55458/1473273.shtml
    http://www.hxtk.com/html/55/55458/1473277.shtml
    http://www.hxtk.com/html/55/55458/1473290.shtml
    http://www.hxtk.com/html/55/55458/1473297.shtml
    http://www.hxtk.com/html/55/55458/1473300.shtml
    http://www.hxtk.com/html/55/55458/1473306.shtml
    http://www.hxtk.com/html/55/55458/1473310.shtml
    http://www.hxtk.com/html/55/55458/1473323.shtml
    http://www.hxtk.com/html/55/55458/1473328.shtml
    http://www.hxtk.com/html/55/55458/1473340.shtml
    http://www.hxtk.com/html/55/55458/1473345.shtml
    http://www.hxtk.com/html/55/55458/1473350.shtml
    http://www.hxtk.com/html/55/55458/1473358.shtml
    http://www.hxtk.com/html/55/55458/1473366.shtml
    http://www.hxtk.com/html/55/55458/1473368.shtml
    http://www.hxtk.com/html/55/55458/1473380.shtml
    http://www.hxtk.com/html/55/55458/1473395.shtml
    http://www.hxtk.com/html/55/55458/1473410.shtml
    http://www.hxtk.com/html/55/55458/1473425.shtml
    http://www.hxtk.com/html/55/55458/1473436.shtml
    http://www.hxtk.com/html/55/55458/1473451.shtml
    http://www.hxtk.com/html/55/55458/1473457.shtml
    http://www.hxtk.com/html/55/55458/1473467.shtml
    http://www.hxtk.com/html/55/55458/1473486.shtml
    http://www.hxtk.com/html/55/55458/1473559.shtml
    http://www.hxtk.com/html/55/55458/1473575.shtml
    http://www.hxtk.com/html/55/55458/1473584.shtml
    http://www.hxtk.com/html/55/55458/1473585.shtml
    http://www.hxtk.com/html/55/55458/1473591.shtml
    http://www.hxtk.com/html/55/55458/1473598.shtml
    http://www.hxtk.com/html/55/55458/1473604.shtml
    http://www.hxtk.com/html/55/55458/1473622.shtml
    http://www.hxtk.com/html/55/55458/1473624.shtml
    http://www.hxtk.com/html/55/55458/1473631.shtml
    http://www.hxtk.com/html/55/55458/1473641.shtml
    http://www.hxtk.com/html/55/55458/1473649.shtml
    http://www.hxtk.com/html/55/55458/1473659.shtml
    http://www.hxtk.com/html/55/55458/1473666.shtml
    http://www.hxtk.com/html/55/55458/1473675.shtml
    http://www.hxtk.com/html/55/55458/1473681.shtml
    http://www.hxtk.com/html/55/55458/1473686.shtml
    http://www.hxtk.com/html/55/55458/1473695.shtml
    http://www.hxtk.com/html/55/55458/1473699.shtml
    http://www.hxtk.com/html/55/55458/1473713.shtml
    http://www.hxtk.com/html/55/55458/1473729.shtml
    http://www.hxtk.com/html/55/55458/1473739.shtml
    http://www.hxtk.com/html/55/55458/1473750.shtml
    http://www.hxtk.com/html/55/55458/1473760.shtml
    http://www.hxtk.com/html/55/55458/1473878.shtml
    http://www.hxtk.com/html/55/55458/1473888.shtml
    http://www.hxtk.com/html/55/55458/1473891.shtml
    http://www.hxtk.com/html/55/55458/1473904.shtml
    http://www.hxtk.com/html/55/55458/1473905.shtml
    http://www.hxtk.com/html/55/55458/1473919.shtml
    http://www.hxtk.com/html/55/55458/1473921.shtml
    http://www.hxtk.com/html/55/55458/1473934.shtml
    http://www.hxtk.com/html/55/55458/1473944.shtml
    http://www.hxtk.com/html/55/55458/1473949.shtml
    http://www.hxtk.com/html/55/55458/1473959.shtml
    http://www.hxtk.com/html/55/55458/1473969.shtml
    http://www.hxtk.com/html/55/55458/1473975.shtml
    http://www.hxtk.com/html/55/55458/1473978.shtml
    http://www.hxtk.com/html/55/55458/1473988.shtml
    http://www.hxtk.com/html/55/55458/1473989.shtml
    http://www.hxtk.com/html/55/55458/1474006.shtml
    http://www.hxtk.com/html/55/55458/1474008.shtml
    http://www.hxtk.com/html/55/55458/1474019.shtml
    http://www.hxtk.com/html/55/55458/1474028.shtml
    http://www.hxtk.com/html/55/55458/1474040.shtml
    http://www.hxtk.com/html/55/55458/1474041.shtml
    http://www.hxtk.com/html/55/55458/1474052.shtml
    http://www.hxtk.com/html/55/55458/1474054.shtml
    http://www.hxtk.com/html/55/55458/1474063.shtml
    http://www.hxtk.com/html/55/55458/1474065.shtml
    http://www.hxtk.com/html/55/55458/1474078.shtml
    http://www.hxtk.com/html/55/55458/1474087.shtml
    http://www.hxtk.com/html/55/55458/1474092.shtml
    http://www.hxtk.com/html/55/55458/1474097.shtml
    http://www.hxtk.com/html/55/55458/1474101.shtml
    http://www.hxtk.com/html/55/55458/1474109.shtml
    http://www.hxtk.com/html/55/55458/1474115.shtml
    http://www.hxtk.com/html/55/55458/1474120.shtml
    http://www.hxtk.com/html/55/55458/1474126.shtml
    http://www.hxtk.com/html/55/55458/1474135.shtml
    http://www.hxtk.com/html/55/55458/1474140.shtml
    http://www.hxtk.com/html/55/55458/1474145.shtml
    http://www.hxtk.com/html/55/55458/1474149.shtml
    http://www.hxtk.com/html/55/55458/1474153.shtml
    http://www.hxtk.com/html/55/55458/1474160.shtml
    http://www.hxtk.com/html/55/55458/1474171.shtml
    http://www.hxtk.com/html/55/55458/1474176.shtml
    http://www.hxtk.com/html/55/55458/1474187.shtml
    http://www.hxtk.com/html/55/55458/1474191.shtml
    http://www.hxtk.com/html/55/55458/1474205.shtml
    http://www.hxtk.com/html/55/55458/1474208.shtml
    http://www.hxtk.com/html/55/55458/1474212.shtml
    http://www.hxtk.com/html/55/55458/1474220.shtml
    http://www.hxtk.com/html/55/55458/1474222.shtml
    http://www.hxtk.com/html/55/55458/1474234.shtml
    http://www.hxtk.com/html/55/55458/1474238.shtml
    http://www.hxtk.com/html/55/55458/1474247.shtml
    http://www.hxtk.com/html/55/55458/1474249.shtml
    http://www.hxtk.com/html/55/55458/1474256.shtml
    http://www.hxtk.com/html/55/55458/1474260.shtml
    http://www.hxtk.com/html/55/55458/1474269.shtml
    http://www.hxtk.com/html/55/55458/1474272.shtml
    http://www.hxtk.com/html/55/55458/1474280.shtml
    http://www.hxtk.com/html/55/55458/1474283.shtml
    http://www.hxtk.com/html/55/55458/1474292.shtml
    http://www.hxtk.com/html/55/55458/1474293.shtml
    http://www.hxtk.com/html/55/55458/1474305.shtml
    http://www.hxtk.com/html/55/55458/1474310.shtml
    http://www.hxtk.com/html/55/55458/1474319.shtml
    http://www.hxtk.com/html/55/55458/1474325.shtml
    http://www.hxtk.com/html/55/55458/1474333.shtml
    http://www.hxtk.com/html/55/55458/1474334.shtml
    http://www.hxtk.com/html/55/55458/1474340.shtml
    http://www.hxtk.com/html/55/55458/1474345.shtml
    http://www.hxtk.com/html/55/55458/1474350.shtml
    http://www.hxtk.com/html/55/55458/1474363.shtml
    http://www.hxtk.com/html/55/55458/1474374.shtml
    http://www.hxtk.com/html/55/55458/1474376.shtml
    http://www.hxtk.com/html/55/55458/1474390.shtml
    http://www.hxtk.com/html/55/55458/1474403.shtml
    http://www.hxtk.com/html/55/55458/1474405.shtml
    http://www.hxtk.com/html/55/55458/1474420.shtml
    http://www.hxtk.com/html/55/55458/1474422.shtml
    http://www.hxtk.com/html/55/55458/1474427.shtml
    http://www.hxtk.com/html/55/55458/1474432.shtml
    http://www.hxtk.com/html/55/55458/1474435.shtml
    http://www.hxtk.com/html/55/55458/1474441.shtml
    http://www.hxtk.com/html/55/55458/1474445.shtml
    http://www.hxtk.com/html/55/55458/1474451.shtml
    http://www.hxtk.com/html/55/55458/1474455.shtml
    http://www.hxtk.com/html/55/55458/1474464.shtml
    http://www.hxtk.com/html/55/55458/1474467.shtml
    http://www.hxtk.com/html/55/55458/1474470.shtml
    http://www.hxtk.com/html/55/55458/1474475.shtml
    http://www.hxtk.com/html/55/55458/1474483.shtml
    http://www.hxtk.com/html/55/55458/1474489.shtml
    http://www.hxtk.com/html/55/55458/1474496.shtml
    http://www.hxtk.com/html/55/55458/1474502.shtml
    http://www.hxtk.com/html/55/55458/1474508.shtml
    http://www.hxtk.com/html/55/55458/1474514.shtml
    http://www.hxtk.com/html/55/55458/1474519.shtml
    http://www.hxtk.com/html/55/55458/1474521.shtml
    http://www.hxtk.com/html/55/55458/1474525.shtml
    http://www.hxtk.com/html/55/55458/1474526.shtml
    http://www.hxtk.com/html/55/55458/1474534.shtml
    http://www.hxtk.com/html/55/55458/1474536.shtml
    http://www.hxtk.com/html/55/55458/1474546.shtml
    http://www.hxtk.com/html/55/55458/1474547.shtml
    http://www.hxtk.com/html/55/55458/1474556.shtml
    http://www.hxtk.com/html/55/55458/1474561.shtml
    http://www.hxtk.com/html/55/55458/1474570.shtml
    http://www.hxtk.com/html/55/55458/1474578.shtml
    http://www.hxtk.com/html/55/55458/1474584.shtml
    http://www.hxtk.com/html/55/55458/1474592.shtml
    http://www.hxtk.com/html/55/55458/1474593.shtml
    http://www.hxtk.com/html/55/55458/1474605.shtml
    http://www.hxtk.com/html/55/55458/1474609.shtml
    http://www.hxtk.com/html/55/55458/1474611.shtml
    http://www.hxtk.com/html/55/55458/1474617.shtml
    http://www.hxtk.com/html/55/55458/1474621.shtml
    http://www.hxtk.com/html/55/55458/1474624.shtml
    http://www.hxtk.com/html/55/55458/1474636.shtml
    http://www.hxtk.com/html/55/55458/1474637.shtml
    http://www.hxtk.com/html/55/55458/1474642.shtml
    http://www.hxtk.com/html/55/55458/1474647.shtml
    http://www.hxtk.com/html/55/55458/1474653.shtml
    http://www.hxtk.com/html/55/55458/1474658.shtml
    http://www.hxtk.com/html/55/55458/1474662.shtml
    http://www.hxtk.com/html/55/55458/1474668.shtml
    http://www.hxtk.com/html/55/55458/1474679.shtml
    http://www.hxtk.com/html/55/55458/1474691.shtml
    http://www.hxtk.com/html/55/55458/1474700.shtml
    http://www.hxtk.com/html/55/55458/1474705.shtml
    http://www.hxtk.com/html/55/55458/1474713.shtml
    http://www.hxtk.com/html/55/55458/1474719.shtml
    http://www.hxtk.com/html/55/55458/1474720.shtml
    http://www.hxtk.com/html/55/55458/1474723.shtml
    http://www.hxtk.com/html/55/55458/1474729.shtml
    http://www.hxtk.com/html/55/55458/1474736.shtml
    http://www.hxtk.com/html/55/55458/1474741.shtml
    http://www.hxtk.com/html/55/55458/1474756.shtml
    http://www.hxtk.com/html/55/55458/1474757.shtml
    http://www.hxtk.com/html/55/55458/1474764.shtml
    http://www.hxtk.com/html/55/55458/1474774.shtml
    http://www.hxtk.com/html/55/55458/1474781.shtml
    http://www.hxtk.com/html/55/55458/1474786.shtml
    http://www.hxtk.com/html/55/55458/1474788.shtml
    http://www.hxtk.com/html/55/55458/1474796.shtml
    http://www.hxtk.com/html/55/55458/1474806.shtml
    http://www.hxtk.com/html/55/55458/1474820.shtml
    http://www.hxtk.com/html/55/55458/1474831.shtml
    http://www.hxtk.com/html/55/55458/1474837.shtml
    http://www.hxtk.com/html/55/55458/1474848.shtml
    http://www.hxtk.com/html/55/55458/1474857.shtml
    http://www.hxtk.com/html/55/55458/1474868.shtml
    http://www.hxtk.com/html/55/55458/1474887.shtml
    http://www.hxtk.com/html/55/55458/1474897.shtml
    http://www.hxtk.com/html/55/55458/1474907.shtml
    http://www.hxtk.com/html/55/55458/1474914.shtml
    http://www.hxtk.com/html/55/55458/1474921.shtml
    http://www.hxtk.com/html/55/55458/1474927.shtml
    http://www.hxtk.com/html/55/55458/1474941.shtml
    http://www.hxtk.com/html/55/55458/1474955.shtml
    http://www.hxtk.com/html/55/55458/1474961.shtml
    http://www.hxtk.com/html/55/55458/1474974.shtml
    http://www.hxtk.com/html/55/55458/1474983.shtml
    http://www.hxtk.com/html/55/55458/1474988.shtml
    http://www.hxtk.com/html/55/55458/1474998.shtml
    http://www.hxtk.com/html/55/55458/1475004.shtml
    http://www.hxtk.com/html/55/55458/1475009.shtml
    http://www.hxtk.com/html/55/55458/1475014.shtml
    http://www.hxtk.com/html/55/55458/1475022.shtml
    http://www.hxtk.com/html/55/55458/1475031.shtml
    http://www.hxtk.com/html/55/55458/1475044.shtml
    http://www.hxtk.com/html/55/55458/1475050.shtml
    http://www.hxtk.com/html/55/55458/1475053.shtml
    http://www.hxtk.com/html/55/55458/1475059.shtml
    http://www.hxtk.com/html/55/55458/1475068.shtml
    http://www.hxtk.com/html/55/55458/1475073.shtml
    http://www.hxtk.com/html/55/55458/1475079.shtml
    http://www.hxtk.com/html/55/55458/1475083.shtml
    http://www.hxtk.com/html/55/55458/1475090.shtml
    http://www.hxtk.com/html/55/55458/1475100.shtml
    http://www.hxtk.com/html/55/55458/1475112.shtml
    http://www.hxtk.com/html/55/55458/1475117.shtml
    http://www.hxtk.com/html/55/55458/1475122.shtml
    http://www.hxtk.com/html/55/55458/1475128.shtml
    http://www.hxtk.com/html/55/55458/1475133.shtml
    http://www.hxtk.com/html/55/55458/1475135.shtml
    http://www.hxtk.com/html/55/55458/1475139.shtml
    http://www.hxtk.com/html/55/55458/1475146.shtml
    http://www.hxtk.com/html/55/55458/1475147.shtml
    http://www.hxtk.com/html/55/55458/1475155.shtml
    http://www.hxtk.com/html/55/55458/1475157.shtml
    http://www.hxtk.com/html/55/55458/1475163.shtml
    http://www.hxtk.com/html/55/55458/1475164.shtml
    http://www.hxtk.com/html/55/55458/1475168.shtml
    http://www.hxtk.com/html/55/55458/1475173.shtml
    http://www.hxtk.com/html/55/55458/1475177.shtml
    http://www.hxtk.com/html/55/55458/1475186.shtml
    http://www.hxtk.com/html/55/55458/1475192.shtml
    http://www.hxtk.com/html/55/55458/1475197.shtml
    http://www.hxtk.com/html/55/55458/1475202.shtml
    http://www.hxtk.com/html/55/55458/1475205.shtml
    http://www.hxtk.com/html/55/55458/1475210.shtml
    http://www.hxtk.com/html/55/55458/1475213.shtml
    http://www.hxtk.com/html/55/55458/1475216.shtml
    http://www.hxtk.com/html/55/55458/1475218.shtml
    http://www.hxtk.com/html/55/55458/1475224.shtml
    http://www.hxtk.com/html/55/55458/1475227.shtml
    http://www.hxtk.com/html/55/55458/1475230.shtml
    http://www.hxtk.com/html/55/55458/1475233.shtml
    http://www.hxtk.com/html/55/55458/1475234.shtml
    http://www.hxtk.com/html/55/55458/1475240.shtml
    http://www.hxtk.com/html/55/55458/1475242.shtml
    http://www.hxtk.com/html/55/55458/1475244.shtml
    http://www.hxtk.com/html/55/55458/1475248.shtml
    http://www.hxtk.com/html/55/55458/1475251.shtml
    http://www.hxtk.com/html/55/55458/1475252.shtml
    http://www.hxtk.com/html/55/55458/1475255.shtml
    http://www.hxtk.com/html/55/55458/1475262.shtml
    http://www.hxtk.com/html/55/55458/1475266.shtml
    http://www.hxtk.com/html/55/55458/1475268.shtml
    http://www.hxtk.com/html/55/55458/1475270.shtml
    http://www.hxtk.com/html/55/55458/1475274.shtml
    http://www.hxtk.com/html/55/55458/1475278.shtml
    http://www.hxtk.com/html/55/55458/1475283.shtml
    http://www.hxtk.com/html/55/55458/1475284.shtml
    http://www.hxtk.com/html/55/55458/1475287.shtml
    http://www.hxtk.com/html/55/55458/1475289.shtml
    http://www.hxtk.com/html/55/55458/1475292.shtml
    http://www.hxtk.com/html/55/55458/1475294.shtml
    http://www.hxtk.com/html/55/55458/1475298.shtml
    http://www.hxtk.com/html/55/55458/1475302.shtml
    http://www.hxtk.com/html/55/55458/1475303.shtml
    http://www.hxtk.com/html/55/55458/1475308.shtml
    http://www.hxtk.com/html/55/55458/1475309.shtml
    http://www.hxtk.com/html/55/55458/1475314.shtml
    http://www.hxtk.com/html/55/55458/1475316.shtml
    http://www.hxtk.com/html/55/55458/1475322.shtml
    http://www.hxtk.com/html/55/55458/1475324.shtml
    http://www.hxtk.com/html/55/55458/1475328.shtml
    http://www.hxtk.com/html/55/55458/1475332.shtml
    http://www.hxtk.com/html/55/55458/1475334.shtml
    http://www.hxtk.com/html/55/55458/1475340.shtml
    http://www.hxtk.com/html/55/55458/1475341.shtml
    http://www.hxtk.com/html/55/55458/1475347.shtml
    http://www.hxtk.com/html/55/55458/1475348.shtml
    http://www.hxtk.com/html/55/55458/1475352.shtml
    http://www.hxtk.com/html/55/55458/1475353.shtml
    http://www.hxtk.com/html/55/55458/1475354.shtml
    http://www.hxtk.com/html/55/55458/1475358.shtml
    http://www.hxtk.com/html/55/55458/1475361.shtml
    http://www.hxtk.com/html/55/55458/1475362.shtml
    http://www.hxtk.com/html/55/55458/1475368.shtml
    http://www.hxtk.com/html/55/55458/1475370.shtml
    http://www.hxtk.com/html/55/55458/1475373.shtml
    http://www.hxtk.com/html/55/55458/1475376.shtml
    http://www.hxtk.com/html/55/55458/1475382.shtml
    http://www.hxtk.com/html/55/55458/1475383.shtml
    http://www.hxtk.com/html/55/55458/1475389.shtml
    http://www.hxtk.com/html/55/55458/1475392.shtml
    http://www.hxtk.com/html/55/55458/1475394.shtml
    http://www.hxtk.com/html/55/55458/1475397.shtml
    http://www.hxtk.com/html/55/55458/1475402.shtml
    http://www.hxtk.com/html/55/55458/1475405.shtml
    http://www.hxtk.com/html/55/55458/1475410.shtml
    http://www.hxtk.com/html/55/55458/1475411.shtml
    http://www.hxtk.com/html/55/55458/1475419.shtml
    http://www.hxtk.com/html/55/55458/1475420.shtml
    http://www.hxtk.com/html/55/55458/1475427.shtml
    http://www.hxtk.com/html/55/55458/1475429.shtml
    http://www.hxtk.com/html/55/55458/1475432.shtml
    http://www.hxtk.com/html/55/55458/1475433.shtml
    http://www.hxtk.com/html/55/55458/1475438.shtml
    http://www.hxtk.com/html/55/55458/1475447.shtml
    http://www.hxtk.com/html/55/55458/1475450.shtml
    http://www.hxtk.com/html/55/55458/1475452.shtml
    http://www.hxtk.com/html/55/55458/1475457.shtml
    http://www.hxtk.com/html/55/55458/1475464.shtml
    http://www.hxtk.com/html/55/55458/1475471.shtml
    http://www.hxtk.com/html/55/55458/1475475.shtml
    http://www.hxtk.com/html/55/55458/1475480.shtml
    http://www.hxtk.com/html/55/55458/1475486.shtml
    http://www.hxtk.com/html/55/55458/1475491.shtml
    http://www.hxtk.com/html/55/55458/1475495.shtml
    http://www.hxtk.com/html/55/55458/1475501.shtml
    http://www.hxtk.com/html/55/55458/1475505.shtml
    http://www.hxtk.com/html/55/55458/1475511.shtml
    http://www.hxtk.com/html/55/55458/1475519.shtml
    http://www.hxtk.com/html/55/55458/1475522.shtml
    http://www.hxtk.com/html/55/55458/1475529.shtml
    http://www.hxtk.com/html/55/55458/1475532.shtml
    http://www.hxtk.com/html/55/55458/1475535.shtml
    http://www.hxtk.com/html/55/55458/1475538.shtml
    http://www.hxtk.com/html/55/55458/1475542.shtml
    http://www.hxtk.com/html/55/55458/1475545.shtml
    http://www.hxtk.com/html/55/55458/1475549.shtml
    http://www.hxtk.com/html/55/55458/1475554.shtml
    http://www.hxtk.com/html/55/55458/1475557.shtml
    http://www.hxtk.com/html/55/55458/1475563.shtml
    http://www.hxtk.com/html/55/55458/1475567.shtml
    http://www.hxtk.com/html/55/55458/1475572.shtml
    http://www.hxtk.com/html/55/55458/1475576.shtml
    http://www.hxtk.com/html/55/55458/1475581.shtml
    http://www.hxtk.com/html/55/55458/1475584.shtml
    http://www.hxtk.com/html/55/55458/1475588.shtml
    http://www.hxtk.com/html/55/55458/1475593.shtml
    http://www.hxtk.com/html/55/55458/1475595.shtml
    http://www.hxtk.com/html/55/55458/1475600.shtml
    http://www.hxtk.com/html/55/55458/1475607.shtml
    http://www.hxtk.com/html/55/55458/1475612.shtml
    http://www.hxtk.com/html/55/55458/1475616.shtml
    http://www.hxtk.com/html/55/55458/1475619.shtml
    http://www.hxtk.com/html/55/55458/1475623.shtml
    http://www.hxtk.com/html/55/55458/1475627.shtml
    http://www.hxtk.com/html/55/55458/1475631.shtml
    http://www.hxtk.com/html/55/55458/1475635.shtml
    http://www.hxtk.com/html/55/55458/1475638.shtml
    http://www.hxtk.com/html/55/55458/1475644.shtml
    http://www.hxtk.com/html/55/55458/1475647.shtml
    http://www.hxtk.com/html/55/55458/1475652.shtml
    http://www.hxtk.com/html/55/55458/1475657.shtml
    http://www.hxtk.com/html/55/55458/1475661.shtml
    http://www.hxtk.com/html/55/55458/1475663.shtml
    http://www.hxtk.com/html/55/55458/1475667.shtml
    http://www.hxtk.com/html/55/55458/1475673.shtml
    http://www.hxtk.com/html/55/55458/1475676.shtml
    http://www.hxtk.com/html/55/55458/1475680.shtml
    http://www.hxtk.com/html/55/55458/1475683.shtml
    http://www.hxtk.com/html/55/55458/1475686.shtml
    http://www.hxtk.com/html/55/55458/1475690.shtml
    http://www.hxtk.com/html/55/55458/1475693.shtml
    http://www.hxtk.com/html/55/55458/1475699.shtml
    http://www.hxtk.com/html/55/55458/1475700.shtml
    http://www.hxtk.com/html/55/55458/1475707.shtml
    http://www.hxtk.com/html/55/55458/1475711.shtml
    http://www.hxtk.com/html/55/55458/1475715.shtml
    http://www.hxtk.com/html/55/55458/1475718.shtml
    http://www.hxtk.com/html/55/55458/1475722.shtml
    http://www.hxtk.com/html/55/55458/1475725.shtml
    http://www.hxtk.com/html/55/55458/1475729.shtml
    http://www.hxtk.com/html/55/55458/1475734.shtml
    http://www.hxtk.com/html/55/55458/1475735.shtml
    http://www.hxtk.com/html/55/55458/1475741.shtml
    http://www.hxtk.com/html/55/55458/1475744.shtml
    http://www.hxtk.com/html/55/55458/1475748.shtml
    http://www.hxtk.com/html/55/55458/1475752.shtml
    http://www.hxtk.com/html/55/55458/1475756.shtml
    http://www.hxtk.com/html/55/55458/1475761.shtml
    http://www.hxtk.com/html/55/55458/1475765.shtml
    http://www.hxtk.com/html/55/55458/1475768.shtml
    http://www.hxtk.com/html/55/55458/1475769.shtml
    http://www.hxtk.com/html/55/55458/1475775.shtml
    http://www.hxtk.com/html/55/55458/1475776.shtml
    http://www.hxtk.com/html/55/55458/1475781.shtml
    http://www.hxtk.com/html/55/55458/1475785.shtml
    http://www.hxtk.com/html/55/55458/1475788.shtml
    http://www.hxtk.com/html/55/55458/1475792.shtml
    http://www.hxtk.com/html/55/55458/1475799.shtml
    http://www.hxtk.com/html/55/55458/1475801.shtml
    http://www.hxtk.com/html/55/55458/1475806.shtml
    http://www.hxtk.com/html/55/55458/1475808.shtml
    http://www.hxtk.com/html/55/55458/1475817.shtml
    http://www.hxtk.com/html/55/55458/1475827.shtml
    http://www.hxtk.com/html/55/55458/1475833.shtml
    http://www.hxtk.com/html/55/55458/1475837.shtml
    http://www.hxtk.com/html/55/55458/1475844.shtml
    http://www.hxtk.com/html/55/55458/1475849.shtml
    http://www.hxtk.com/html/55/55458/1475850.shtml
    http://www.hxtk.com/html/55/55458/1475853.shtml
    http://www.hxtk.com/html/55/55458/1475857.shtml
    http://www.hxtk.com/html/55/55458/1475860.shtml
    http://www.hxtk.com/html/55/55458/1475863.shtml
    http://www.hxtk.com/html/55/55458/1475865.shtml
    http://www.hxtk.com/html/55/55458/1475871.shtml
    http://www.hxtk.com/html/55/55458/1475874.shtml
    http://www.hxtk.com/html/55/55458/1475879.shtml
    http://www.hxtk.com/html/55/55458/1475882.shtml
    http://www.hxtk.com/html/55/55458/1475890.shtml
    http://www.hxtk.com/html/55/55458/1475894.shtml
    http://www.hxtk.com/html/55/55458/1475902.shtml
    http://www.hxtk.com/html/55/55458/1475903.shtml
    http://www.hxtk.com/html/55/55458/1475908.shtml
    http://www.hxtk.com/html/55/55458/1475911.shtml
    http://www.hxtk.com/html/55/55458/1475916.shtml
    http://www.hxtk.com/html/55/55458/1475918.shtml
    http://www.hxtk.com/html/55/55458/1475922.shtml
    http://www.hxtk.com/html/55/55458/1475926.shtml
    http://www.hxtk.com/html/55/55458/1475930.shtml
    http://www.hxtk.com/html/55/55458/1475932.shtml
    http://www.hxtk.com/html/55/55458/1475939.shtml
    http://www.hxtk.com/html/55/55458/1475941.shtml
    http://www.hxtk.com/html/55/55458/1475950.shtml
    http://www.hxtk.com/html/55/55458/1475953.shtml
    http://www.hxtk.com/html/55/55458/1475961.shtml
    http://www.hxtk.com/html/55/55458/1475963.shtml
    http://www.hxtk.com/html/55/55458/1475969.shtml
    http://www.hxtk.com/html/55/55458/1475974.shtml
    http://www.hxtk.com/html/55/55458/1475979.shtml
    http://www.hxtk.com/html/55/55458/1475982.shtml
    http://www.hxtk.com/html/55/55458/1475988.shtml
    http://www.hxtk.com/html/55/55458/1475991.shtml
    http://www.hxtk.com/html/55/55458/1475996.shtml
    http://www.hxtk.com/html/55/55458/1475998.shtml
    http://www.hxtk.com/html/55/55458/1476006.shtml
    http://www.hxtk.com/html/55/55458/1476009.shtml
    http://www.hxtk.com/html/55/55458/1476015.shtml
    http://www.hxtk.com/html/55/55458/1476018.shtml
    http://www.hxtk.com/html/55/55458/1476025.shtml
    http://www.hxtk.com/html/55/55458/1476027.shtml
    http://www.hxtk.com/html/55/55458/1476037.shtml
    http://www.hxtk.com/html/55/55458/1476039.shtml
    http://www.hxtk.com/html/55/55458/1476045.shtml
    http://www.hxtk.com/html/55/55458/1476047.shtml
    http://www.hxtk.com/html/55/55458/1476056.shtml
    http://www.hxtk.com/html/55/55458/1476058.shtml
    http://www.hxtk.com/html/55/55458/1476066.shtml
    http://www.hxtk.com/html/55/55458/1476067.shtml
    http://www.hxtk.com/html/55/55458/1476074.shtml
    http://www.hxtk.com/html/55/55458/1476076.shtml
    http://www.hxtk.com/html/55/55458/1476082.shtml
    http://www.hxtk.com/html/55/55458/1476084.shtml
    http://www.hxtk.com/html/55/55458/1476091.shtml
    http://www.hxtk.com/html/55/55458/1476093.shtml
    http://www.hxtk.com/html/55/55458/1476101.shtml
    http://www.hxtk.com/html/55/55458/1476103.shtml
    http://www.hxtk.com/html/55/55458/1476110.shtml
    http://www.hxtk.com/html/55/55458/1476113.shtml
    http://www.hxtk.com/html/55/55458/1476118.shtml
    http://www.hxtk.com/html/55/55458/1476122.shtml
    http://www.hxtk.com/html/55/55458/1476128.shtml
    http://www.hxtk.com/html/55/55458/1476130.shtml
    http://www.hxtk.com/html/55/55458/1476137.shtml
    http://www.hxtk.com/html/55/55458/1476140.shtml
    http://www.hxtk.com/html/55/55458/1476144.shtml
    http://www.hxtk.com/html/55/55458/1476147.shtml
    http://www.hxtk.com/html/55/55458/1476151.shtml
    http://www.hxtk.com/html/55/55458/1476154.shtml
    http://www.hxtk.com/html/55/55458/1476162.shtml
    http://www.hxtk.com/html/55/55458/1476168.shtml
    http://www.hxtk.com/html/55/55458/1476172.shtml
    http://www.hxtk.com/html/55/55458/1476173.shtml
    http://www.hxtk.com/html/55/55458/1476186.shtml
    http://www.hxtk.com/html/55/55458/1476193.shtml
    http://www.hxtk.com/html/55/55458/1476199.shtml
    http://www.hxtk.com/html/55/55458/1476207.shtml
    http://www.hxtk.com/html/55/55458/1476212.shtml
    http://www.hxtk.com/html/55/55458/1476217.shtml
    http://www.hxtk.com/html/55/55458/1476222.shtml
    http://www.hxtk.com/html/55/55458/1476227.shtml
    http://www.hxtk.com/html/55/55458/1476233.shtml
    http://www.hxtk.com/html/55/55458/1476238.shtml
    http://www.hxtk.com/html/55/55458/1476243.shtml
    http://www.hxtk.com/html/55/55458/1476249.shtml
    http://www.hxtk.com/html/55/55458/1476254.shtml
    http://www.hxtk.com/html/55/55458/1476260.shtml
    http://www.hxtk.com/html/55/55458/1476265.shtml
    http://www.hxtk.com/html/55/55458/1476271.shtml
    http://www.hxtk.com/html/55/55458/1476277.shtml
    http://www.hxtk.com/html/55/55458/1476281.shtml
    http://www.hxtk.com/html/55/55458/1476284.shtml
    http://www.hxtk.com/html/55/55458/1476292.shtml
    http://www.hxtk.com/html/55/55458/1476297.shtml
    http://www.hxtk.com/html/55/55458/1476298.shtml
    http://www.hxtk.com/html/55/55458/1476305.shtml
    http://www.hxtk.com/html/55/55458/1476306.shtml
    http://www.hxtk.com/html/55/55458/1476313.shtml
    http://www.hxtk.com/html/55/55458/1476314.shtml
    http://www.hxtk.com/html/55/55458/1476322.shtml
    http://www.hxtk.com/html/55/55458/.shtml






     


    展开全文
  • Item 24提到,如果所有参数... 但是在类模板,需要所有参数隐式转换函数应当声明为友元并定义在类模板。 模板化的Rational 既然是Item 24的推广,那么我们先把Item24的Rational和operator*模板化。得到...

    Item 24中提到,如果所有参数都需要隐式类型转换,该函数应当声明为非成员函数。Item 24是以Rationaloperator*为例子展开的,本文把这个观点推广到类模板和函数模板。 但是在类模板中,需要所有参数隐式转换的函数应当声明为友元并定义在类模板中。

    模板化的Rational

    既然是Item 24的推广,那么我们先把Item24中的Rationaloperator*模板化。得到如下代码:

    template<typename T>
    class Rational {
    public:
      Rational(const T& numerator = 0, const T& denominator = 1);
      const T numerator() const;           
      const T denominator() const;        
    };
     
    template<typename T>
    const Rational<T> operator*(const Rational<T>& lhs, const Rational<T>& rhs){}

    Item 20解释了为什么Rational的参数是常量引用;Item 28解释了为什么numerator()返回的是值而不是引用;Item 3解释了为什么numerator()返回的是const。

     模板参数推导出错

    上述代码是Item24直接模板化的结果,看起来很完美但它是有问题的。比如我们有如下的调用:

    Rational<int> oneHalf(1, 2);            // OK
    Rational<int> result = oneHalf * 2;     // Error!

    为什么第二条会出错呢?因为编译器无法推导出合适的模板参数来实例化Rational<T>。 模板参数的推导包括两部分:

    • 根据onHalf,它的类型是Rational<int>,很容易知道接受oneHalfoperator*<T>中模板参数T应该是int
    • 根据2的模板参数推导却不那么顺利,编译器不知道如何将实例化operator*<T>才能使得它接受一个int类型的2

    可能你会希望编译器将2的类型推导为Rational<int>,再进行隐式转换。但在编译器中模板推导和函数调用是两个过程: 隐式类型转换发生在函数调用时,而在函数调用之前编译器需要实例化一个函数。而在模板实例化的过程中,编译器无从推导T的类型。

    声明为友元函数

    为了让编译器知道T是什么,我们可以在类模板中通过friend声明来引用一个外部函数。

    template<typename T>
    class Rational {
    public:
        friend const Rational operator*(const Rational& lhs, const Rational& rhs);
    };
     
    template<typename T>
    const Rational<T> operator*(const Rational<T>& lhs, const Rational<T>& rhs){}

    Rational<T>中声明的friend没有添加模板参数T,这是一个简便写法,它完全等价于: friend const Rational<T> operator*(const Rational<T>& lhs, const Rational<T>& rhs);

    因为类模板实例化后,T总是已知的,因而那个friend函数的签名会被Rational模板类声明。 这样,result = oneHalf * 2便可以编译通过了,但链接会出错。 虽然在类中声明了friend operator*,然而编译器却不会实例化该声明对应的函数。 因为函数是我们自己声明的,那么编译器认为我们有义务自己去定义那个函数。

    在类中给出定义

    那我们就在声明operator*时直接给出定义:

    template<typename T>
    class Rational {
    public:
        friend const Rational operator*(const Rational& lhs, const Rational& rhs){
            return Rational(lhs.numerator() * rhs.numerator(), lhs.denominator() * rhs.denominator());
        }
    };

    这样混合模式的调用result = oneHalf * 2终于可以编译、链接并且运行了。到这里想必问题已经很清楚了:

    1. 为了对所有参数支持隐式类型转换,operator*需要声明为非成员函数;
    2. 为了让编译器推导出模板参数,operator*需要在类中声明;
    3. 在类中声明非成员函数的唯一办法便是声明为friend
    4. 声明的函数的同时我们有义务给出函数定义,所以在函数定义也应当放在friend声明中。

    调用辅助函数

    虽然operator*可以成功运行了,但定义在类定义中的函数是inline函数,见Item 30。 如果operator*函数体变得很大,那么inline函数就不再合适了,这时我们可以让operator*调用外部的一个辅助函数:

    template<typename T> class Rational;
    template<typename T>
    const Rational<T> doMultiply(const Rational<T>& lhs, const Rational<T>& rhs);
     
    template<typename T>
    class Rational{
    public:
        friend Rational<T> operator*(const Rational<T>& lhs, const Rational<T>& rhs){
            return doMultiply(lhs, rhs);
        }
    };

    doMultiply仍然是不支持混合模式调用的,然而doMultiply只会被operator*调用。 operator*将会完成混合模式的兼容,然后用统一的Rational<T>类型参数来调用doMultiply

    展开全文
  • C++转换函数

    2017-08-11 23:12:07
    一、conversion function, 转换函数 ...在类的声明,通过指定关键字operator,并在其后加上转换的目标类型后,我们就可以声明转换函数。 1. 特点 转换函数采用如下的一般形式:  operator type

    一、conversion function, 转换函数

    转换函数(conversion function)是一种特殊类型的类成员函数。它定义了一个由用户定义的转换,以便把一个类对象转换成某种其他的类型。 
    在类的声明中,通过指定关键字operator,并在其后加上转换的目标类型后,我们就可以声明转换函数。

    1. 特点

    转换函数采用如下的一般形式: 
    operator type() 
    这里的type可用内置类型、类类型或typedef名取代。但是不允许type表示数组或函数。 
    转换函数必须是成员函数,它的声明不能指定返回类型和参数列表。 
    如果转换函数没有类成员进行修改,可以在函数声明中增加const关键字,增加代码的健壮性。

    2. 例子

    以下代码展示了类Fraction中的转换函数operator double() const

    class Fraction {
    public:
        Fraction(int num, int den) :
            m_numerator(num), m_denominator(den) {}
    
        operator double() const {
            return (double) (m_numerator / m_denominator);
        }
    
    private:
        int m_numerator;  // 分子
        int m_denominator;  // 分母
    };
    
    Fraction f(3, 5);
    double d = 4 + f;  // 调用operater double将f转换成double
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    3. 说明

    double d = 4 + f;这一语句会首先查找Fraction是否有重载操作符 operator + (double, Fraction) 的函数,由于没有,所以调用会转换函数operator double() const

    另外,转换函数除了可以将一个类型转换成另一个基本类型,还可以将一个类型转换成另一个复合类型(例如string类型)。

    4. 作用

    把这种东西(A)转换成别的东西(B)

    二、non-explicit-one-argument constructor

    1. 例子

    class Fraction 
    {
        Fraction(int num, int den=1) :
            m_numerator(num), m_denominator(den) {}
    
        Fraction operator + (const Fraction& f) {
            return Fraction(...);
        }
    
    private:
        int m_numerator;  // 分子
        int m_denominator;  // 分母
    };
    
    Fraction f(3, 5);
    Fraction d2 = f + 4;  // 调用non-explicit ctor将4转换成Fraction(4, 1),然后再调用operator +
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    2. 说明

    构造函数虽然有two parameters(两个形参),但只有one argument,且构造函数前面没有explicit,所以叫做non-explicit-one-argument constructor。

    3. 作用

    把别的东西(B)转换成这种东西(A)

    三、conversion function vs. non-explicit-one-argument constructor

    1. 例子

    class Fraction 
    {
        Fraction(int num, int den=1) :
            m_numerator(num), m_denominator(den) {}
    
        operator double() const {
            return (double) (m_numerator / m_denominator);
        }
    
        Fraction operator + (const Fraction& f) {
            return Fraction(...);
        }
    
    private:
        int m_numerator;  // 分子
        int m_denominator;  // 分母
    };
    
    Fraction f(3, 5);
    Fraction d2 = f + 4;  // [Error] ambiguous
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    2. 说明

    上述的代码会导致二义性的出现,即 
    - 可以将4转换成Fraction 
    - 可以将f转换成double,与4相加得到一个double,然后再转换成Fraction

    为了使得编译通过,可以将Fraction d2 = f + 4;改成double d2 = f + 4;即可。

    四、explicit-one-argument constructor

    1. 例子

    class Fraction 
    {
        explicit Fraction(int num, int den=1) :
            m_numerator(num), m_denominator(den) {}
    
        operator double() const {
            return (double) (m_numerator / m_denominator);
        }
    
        Fraction operator + (const Fraction& f) {
            return Fraction(...);
        }
    
    private:
        int m_numerator;  // 分子
        int m_denominator;  // 分母
    };
    
    Fraction f(3, 5);
    Fraction d2 = f + 4;  // [Error] convertion from double to Fraction requested
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    2. 说明

    由于在构造函数前面增加了explicit关键字,所以不能将4转换成Fraction类型;也不能先将f转换成double类型,与4相加后再将double转换成Fraction。

    3. 作用

    explicit这个关键字基本只出现在构造函数前面,意思是需要明确地需要调用这个构造函数才能调用,不存在暗中、自动的转换操作。

    五、转换函数在STL中的运用

    1. 例子

    template<class Alloc>
    class vector<bool, Alloc>
    {
    public:
        typedef __bit_reference reference;
    
    protected:
        reference operator[] (size_type n) {
            return *(begin() + defference_type(n));
        }
    };
    
    struct __bit_reference {
        unsigned int *p;
        unsigned int mask;
    
    public:
        operator bool() const {
            return ! ( ! ( *p & mask) ); 
        }
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    2. 说明

    class vector <bool, Alloc>这里是模板的偏特化。

    reference operator[] (size_type n)返回vector元素的类型,从vector类型的声明看,应该是返回 一个bool类型的值,可是现在却返回了一个referecnce类型。 
    reference类型亦即__bit_reference类型,故__bit_reference类型需要转换成bool类型。 
    这样就要求__bit_reference类型需包含一个转换函数,可以将__bit_reference类型转换成bool类型,这正是转换函数operator bool() const的作用。

    参考资料

    1. 侯捷《C++最佳编程实践》视频,极客班,2015
    2. 《C++ Primer》中文版,第三版,潘爱民等译,2002
    转载:http://blog.csdn.net/lihao21
    展开全文
  • Item 24提到,如果所有参数都需要隐式类型转换,该函数应当声明为非成员函数。 Item 24是以Rational和operator*为例子展开的,本文把这个观点推广到类模板和函数模板。 但是在类模板,需要所有参
  • 用转换构造函数可以将一个指定类型的数据转换为类的对象。但是不能反过来将一个类的对象转换为一个其他类型的数据(例如将一个Complex类对象转换成...如果已声明了一个Complex类,可以Complex类中这样定义类型转换函数
  • 转换函数又称类型强制转换成员函数,它是类中的一个非静态成员函数。它的定义格式如下: 代码如下: class <类型说明符1> { public: operator <类型说明符2>(); … } 这个转换函数定义了由<类型说明符...
  • 类型转换函数

    2014-09-01 14:06:06
    例如,如果已声明了一个Complex类,可以Complex类中这样定义类型转换函数 : operator double() { return m_dReal; } 函数返回double型变量m_dReal的值. 它的作用是将一个Complex类对象转换为一个...
  • C++ 类型转换函数

    2016-10-25 11:32:00
     用转换构造函数可以将一个指定类型的数据转换为类的对象。但是不能反过来将一个类的对象转换为一个其他类型的数据(例如将一个Complex类对象转换成...如果已声明了一个Complex类,可以Complex类中这样定义类型转
  • 【c/c++】类型转换函数(类型转换运算符重载函数)

    千次阅读 多人点赞 2016-01-04 18:09:10
    用转换构造函数可以将一个指定类型的数据转换为类的对象。但是不能反过来将一个类的对象转换为一个其他类型的数据(例如将一个Complex类对象转换成...如果已声明了一个Complex类,可以Complex类中这样定义类型转换函数
  • C++类型转换函数

    2013-06-17 17:15:01
    C++提供类型转换函数(type conversion function)来解决这个问题。类型转换函数的作用是将一个类的对象转换成另一类型的数据。如果已声明了一个Complex类,可以Complex类中这样定义类型转换函数
  • 用*转换构造函数可以将一个指定类型的数据转换为类的对象*。但是不能反过来将一个类的...如果已声明了一个Complex类,可以Complex类中这样定义类型转换函数: operator double( ) { return real; } 函数返回dou
  • 类型转换操作符(type conversion operator)是一种特殊的类成员函数,它定义将...转换函数又称类型强制转换成员函数,它是类中的一个非静态成员函数。它的定义格式如下:  class  {  public:  operator ();
  • 实例很简单,定义一个基类和子类,基类有两个函数talk和eat,其中eat用virtual关键字声明子类重写了talk和eat函数以示区分,为了能分辨出来到底调用了基类还是子类的函数。 基类指针指向基类对象和派生指针...
  • 转换构造函数

    千次阅读 2017-12-26 14:56:13
    通常使用转换构造函数将一个指定的...2、这个类中定义一个只有一个参数的构造函数,参数是待转换类型的数据,在函数体中指定转换的方法**#include using namespace std; class complex { public: complex() { }
  • 类型转换操作符(type conversion operator)是一种特殊的类成员函数,它定义将类...转换函数又称类型强制转换成员函数,它是类中的一个非静态成员函数。它的定义格式如下:  class  {  public:  operator ();
  • 其中一个文件,我想定义一个可以全局命名空间用作速记的函数.由于作曲家的要求,该需要被命名空间.我的问题:有什么方法可以通过微小的改动来实现这个目的吗?MyClass.php:namespace Jodes;class MyClass...
  • C++explict声明构造函数的作用

    千次阅读 2013-04-24 10:59:26
    C++ , 如果一个有只有一个参数的构造函数,C++ 允许一种特殊的声明类变量的方式。这种情况下,可以直接将一个对应于构造函数参数类型的数据直接赋值给变量,编译器编译时会自动进行类型转换,将对应于...
  • 从编码到运行 首先笔者想要探讨一下一个C++项目是如何从文本文件生成可执行文件的。...c++开发广泛使用声明和实现分开的开发形式,其编译过程是分离式编译,就是说各个cpp文件完全分开编译,然后
  • 有两种内联函数声明方法,一种是在函数前使用inline关见字,另一种是在类的内部定义函数的代码,这样的函数将自动转换为内联函数,而且没必要将inline放在函数前面.3.内联是一种对编译器的请求,下面这些情况会...
  •  用转换构造函数可以将一...C++提供类型转换函数(type conversion function)来解决这个问题。类型转换函数的作用是将一个类的对象转换成另一类型的数据。如果已声明了一个Complex类,可以Complex类中这样定义类型

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,453
精华内容 581
关键字:

在类中声明转换函数