niusouti.com
更多“若有如下函数模板定义,则正确使用该函数模板的语句是()。templatevoidadd(typea,typeb,type} ”相关问题
  • 第1题:

    补充完整下面的模板定义: template//Type为类型参数 class Xtwo{//由两个Type类型

    补充完整下面的模板定义:

    template<class Type> //Type为类型参数

    class Xtwo{ //由两个Type类型的数据成员构成的模板类

    Type a;

    Type b;

    public:

    Xtwo(Type aa=0,Type bb=0):a(aA) ,b(bB) { }

    int Compare( ){ //比较a和b的大小

    if(a>B) return 1;

    else if(a==B) return 0;

    else return-1;

    }

    Type Sum( ){return a+b;} //返回a和b之和

    Type Mult( ); //函数声明,返回a和b之乘积

    };

    template<class Type>

    ______ ::Mult( ){return a*b;} //Mult函数的类外定义


    正确答案:Xtwo
    Xtwo

  • 第2题:

    已知:double A(double A) {return++a;}和int A(in A) {return++a;}是一个函数模板的两个实例,则该函数模板定义为【 】


    正确答案:templatetypename T> TA(TA) {return a++)
    templatetypename T> TA(TA) {return a++,) 解析:本题考核函数模板的定义。通过两个实例知道该例中只有一种数据类型,所以在定义模板时只需定义一个模板参数T。

  • 第3题:

    补充完整下面的模板定义:

    template<class//Type> //Type为类型参数

    class Xtwo{//由两个Type类型的数据成员构成的模板类

    Type a;

    Type b;

    public:

    Xtwo(Type aa=O,Type bb=O):a(a.A),b(bB){}

    int Compare(){//比较a和b的大小

    if(a>B)retum 1;

    else if(a==@B)@return 0;

    else return-1:

    f

    }

    Type Sum();{return a+b;}//返回a与b的和

    Type Mult(); //函数声明,返回a和b的乘积

    };

    template<class Type>

    【 】::Mult(){return a*b;}//Mult函数的类外定义


    正确答案:Type Xtwo
    Type Xtwo 解析:类外函数要先定义函数返回类型Type,其次要加上类名和作用域Xtwo。

  • 第4题:

    ( 15 )补充完整下面的模板定义:

    template<class Type> //Type 为类型参数

    class Xtwo{ // 由两个 Type 类型的数据成员构成的模板类

    Type a;

    Type b;

    public:

    Xtwe ( Type aa=0, Type bb=0 ) : a ( aa ) , b ( bb ) {}

    int Ccmpare () {// 比较 a 和 b 的大小

    if ( a>b ) returm 1;

    else if ( a==b ) return 0;

    else return -1;

    }

    Type Snm () {return a+b;} // 返回 a 和 b 之和

    Type Mult ( ) ; // 函数声明,返回 a 和 b 之乘积

    } ;

    Template<class Type>

    【 15 】 : : Mult () {return a*b;} //Mult 函数的类外定义


    正确答案:

  • 第5题:

    已知int DBL (int n){return n+n;}和long DBL (long n){return n+n}是一个函数模板的两个实例,则该函数模板的定义是______。


    正确答案:templateclass T>T DBL(Tn){return n+n;}
    templateclass T>T DBL(Tn){return n+n;} 解析:本题考核函数模板的使用。函数模板的一般说明形式如下:template类型形参表>返回类型函数名(形参表){//函数体)。函数调用方式为:函数名(实参表);。形参表中的类型以实参表中的实际类型为依据。由此易得答案。