在下列模板说明中,正确的是()A、template〈typename T1,T2〉B、template〈class T1,T2〉C、template〈typename T1,typename T2〉D、template(typedef T1,typedef T2)

题目

在下列模板说明中,正确的是()

  • A、template〈typename T1,T2〉
  • B、template〈class T1,T2〉
  • C、template〈typename T1,typename T2〉
  • D、template(typedef T1,typedef T2)

相似考题
更多“在下列模板说明中,正确的是()A、template〈typename T1,T2〉B、template〈class T1,T2〉C、template〈typename T1,typename T2〉D、template(typedef T1,typedef T2)”相关问题
  • 第1题:

    有如下函数模板定义:templateT2 plus T1 t1,T3 t3){retur

    有如下函数模板定义: template<typename T1,typename T2,typename T3> T2 plus T1 t1,T3 t3){return t1+t3;} 则以下调用中正确是

    A.plus(3,5L);

    B.plus<>(3,5L);

    C.plus<int>(3,5L);

    D.plus<int,double>(3,5L);


    正确答案:D
    解析:本题考核函数模板的使用。C++中对函数模板的调用有时候只使用了函数实参,而没有使用模板实参,模板实参都被省略了,但模板实参的省略并不是必然的,而是有条件。模板实参不能省略的情况有:从模板函数实参表获得的信息有矛盾:需要获得特定类型的返回值,而不管参数的类型如何:虚拟类型参数没有出现在模板函数的形参中;函数模板含有常规形参。题中定义的函数模板中虚拟类型参数T2没有出现在模板函数的形参列表中,所以在调用时不能省略,D选项的调用省略了T3,这是允许的。

  • 第2题:

    下列对模板的声明中,正确的是A.templateB.templateC.template

    下列对模板的声明中,正确的是

    A.template<T>

    B.template<class T1,T2>

    C.template<class T1,class T2>

    D.tamplate<class T1;class T2>


    正确答案:C
    解析:本题考核模板的定义。模板定义的类型参数表>中包含一个或多个由逗号分隔的类型参数项,每一项由关键字class后跟一个用户命名的标识符,此标识符为类型参数,它不是一种数据类型,但可以同一般数据类型一样使用。在使用类模板时,必须将其实例化,即用实际的数据类型代替它。

  • 第3题:

    已知一个函数模板定义为: template T1 FUN(T2 n){return n*5.0;} 若

    已知一个函数模板定义为:

    template<typename T1, typename T2>

    T1 FUN(T2 n){return n*5.0;}

    若要求以int型数据7为函数实参调用该模板函数,并返回一个double型数据,则该调用应表示为______。


    正确答案:FUNdouble>(7)或FUNdoubleint>(7)
    FUNdouble>(7)或FUNdouble,int>(7) 解析:此题考查的是函数模板的调用。本题模板函数的返回值类型为T1,形参类型为T2。题目要求用int型参数7调用,并返回一个double型数据。故调用格式为FUNdouble,int>(7)。也可省略T2的类型int,简写为FUNdouble>(7)。

  • 第4题:

    下列对模板的声明中正确的是()。A.templateB.templateC.template

    下列对模板的声明中正确的是( )。

    A.template<T>

    B.template<class T1,T2>

    C.template<classT1,class T2>

    D.template<class T1;class T2>


    正确答案:C

  • 第5题:

    下面不属于同一函数模板的是()。A.template t1 max(t1 &a,t1 &b) {…}template<

    下面不属于同一函数模板的是( )。

    A.template<class t1> t1 max(t1 &a,t1 &b) {…}template<class t2> t2 max(t2 &a,t2 &b) {…}

    B.template<class t1>t1 max(t1 a,t1 b){…}template<class t2>t2 max(t2 &a,t2 &b){…}

    C.template<class t1> t1 max(t1 * a,t1 * b) {…} template<class t2> t2 max(t2 &a,t2 &b) {…}

    D.template<class t1>t1 max(t1 a,t1 b){…}template<class t2>t2 max(t2 &a,t2 &b,t2 c){…}


    正确答案:D
    解析:函数模板的重载是靠模板参数的数量不同来区分的,因为函数模板是抽象的,有待于进一步实例化,所以靠参数类型无法区别调用哪个函数模板。

  • 第6题:

    有如下函数模板定义: template T2 plus(T1 t1,T3 t3){re

    有如下函数模板定义: template <typename T1,typename T2,typename T3> T2 plus(T1 t1,T3 t3){return t1+t3;}

    A.plus(3,5L);

    B.plus<>(3,5L);

    C.plus<int>(3,5L);

    D.plus<int, double>(3,5L);


    正确答案:D
    解析:本题考核函数模板的使用。C++中对函数模板的调用有时候只使用了函数实参,而没有使用模板实参,模板实参都被省略了,但模板实参的省略并不是必然的,而是有条件。模板实参不能省略的情况有:从模板函数实参表获得的信息有矛盾;需要获得特定类型的返回值,而不管参数的类型如何:虚拟类型参数没有出现在模板函数的形参中;函数模板含有常规形参。题中定义的函数模板中虚拟类型参数T2没有出现在模板函数的形参列表中,所以在调用时不能省略,D选项的调用省略了T3,这是允许的。

  • 第7题:

    下面对模板的声明正确的是 ______。A.templateB.templateC.template

    下面对模板的声明正确的是 ______。

    A.template<T>

    B.template<class T1,T2>

    C.template<classT1,classT2>

    D.template<classT1; classT2>


    正确答案:C

  • 第8题:

    以下对模板的说明,正确的是()。A.templateB.templateC.template

    以下对模板的说明,正确的是( )。

    A.template<T>

    B.template<classT1,T2>

    C.template<class T1,class T2>

    D.template<class T1;class T2>


    正确答案:C

  • 第9题:

    有如下函数模板定义: template<typename T1,typename T2,typename T3) T2 plus(T1 t1,T3 t3){return t1+t3;} 则以下调用正确是( )。

    A.plus(3,5L);

    B.plus<>(3,5L);

    C.plus<int>(3,5L);

    D.plus<int,double)(3,5L);


    正确答案:D
    解析: C++中对函数模板的调用有时候只使用了函数实参,而没有使用模板实参,模板实参都被省略了,但模板实参的省略并不是必然的,而是有条件。从模板函数实参表获得的信息有矛盾:需要获得特定类型的返回值,而不管参数的类型如何;虚拟类型参数滑出现在模板函数的形参中;函数模板含有常规形参。题中定义的函数模板中虚拟类型参数T2没有出现在模板函数的形参列表中,所以在调用时不能省略,D选项的调用省略了T3,这是允许的。

  • 第10题:

    有如下模板声明:templateclass A;下列声明中,与上述声明不等价的是A.t

    有如下模板声明: template<typename T1,typename T2>class A; 下列声明中,与上述声明不等价的是

    A.template<class T1,class T2>class A;

    B.template<class T1,typename T2>class A;

    C.template<typename T1,class T2>class A;

    D.template<typename T1,T2>class A;


    正确答案:D
    解析:在模板定义中,一般情况下,class和typename可以互换。在选项D中,T2没有类型参数限制定义,所以和题干给出的定义不同。

  • 第11题:

    下列对模板的声明中正确的是A.templateB.templateC.templateD

    下列对模板的声明中正确的是

    A.template<T>

    B.template<class T1,T2>

    C.template<classT1,classT2>

    D.template<classT1;classT2>


    正确答案:C
    解析:本题考核模板的定义。模板定义的类型参数表>中包含一个或多个由逗号分隔的类型参数项,每一项由关键字class后跟一个用户命名的标识符,此标识符为类型参数,它不是一种数据类型,但可以同一般数据类型一样使用。在使用类模板时,必须将其实例化,即用实际的数据类型代替它。

  • 第12题:

    单选题
    有如下模板声明:template class A;下列声明中,与上述声明不等价的是(  )。
    A

    template<class T1,class T2> class A;

    B

    template<class T1,typename T2> class A;

    C

    template<typename T1,class T2> class A;

    D

    template<typename T1,T2> class A;


    正确答案: B
    解析:
    在类模板中,数据类型本身是它的参数,因而是一种参数化类型的类,是类的生成器。对于本题来说,模板形参表中包括类型Tl和T2两个类型参数,D项,T1说明其类型,而T2没有说明其类型,与题干中的模板说明不一致。

  • 第13题:

    下列对模板的声明,正确的是()。A.templateB.templateC.template

    下列对模板的声明,正确的是( )。

    A.template<T>

    B.template<classT1,T2>

    C.template<class T1,classT2>

    D.template<class T1;class T2>


    正确答案:C
    解析:模板定义的类型参数表>中包含一个或多个由逗号分隔的类型参数项,每一项由关键字class后跟一个用户命名的标识符,此标识符为类型参数,它不是一种数据类型,但可以同一般数据类型一样使用。在使用类模板时,必须将其实例化,即用实际的数据类型代替它。

  • 第14题:

    下列是模板声明的开始部分,其中正确的是______ 。A.templateB.template C.templa

    下列是模板声明的开始部分,其中正确的是______ 。

    A.template<T>

    B.template <class T1,T2>

    C.template <class T1,class T2>

    D.template <class T1;class T2>


    正确答案:C
    解析:模板声明的语法定义。

  • 第15题:

    有如下函数模板定义: template T1 Fun(T2 n){return n*5.0;} 若要求

    有如下函数模板定义:

    template<typename T1, Typename T2>

    T1 Fun(T2 n){return n*5.0;}

    若要求以int型数据9作为函数实参调用该模板,并返回一个double型数据,则该调用应表示为( )。

    A) FUN(9)

    B) FUN<9>

    C) FUN<double>[9]

    D) FUN<9>(doubl

    A.

    B.

    C.

    D.


    正确答案:C

  • 第16题:

    下列模板的声明中,正确是A.templateB.templateC.templateD.

    下列模板的声明中,正确是

    A.template<T>

    B.template<class T1,T2>

    C.template<class T1,class T2>

    D.template<class T1 ;class T2>


    正确答案:C
    解析:本题考核模板的定义。模板定义的类型参数表>中包含一个或多个由逗号分隔的类型参数项,每一项由关键字class后跟一个用户命名的标识符,此标识符为类型参数,它不是一种数据类型,但可以同一般数据类型一样使用。在使用类模板时,必须将其实例化,即用实际的数据类型代替它。

  • 第17题:

    当运算符重载为成员函数时,如果函数参数表中没有参数,则表明该重载为单目运算符,操作数就为该对象本身;如果函数参数表中有一个参数,则表示该重载为双目运算符,另外一个操作数为该对象本身。

    A.template<class T1,class T2>class A;

    B.template<class T1,typename T2>class A;

    C.template<typename T1,class T2>class A;

    D.template<typename T1,T2>class A;


    正确答案:D
    解析:在模板定义中,一般情况下,class和typename可以互换。在选项D中,T2没有类型参数限制定义,所以和题干给出的定义不同。

  • 第18题:

    下列对模板的声明,正确的是()。A.templateB.templateC.template

    下列对模板的声明,正确的是( )。

    A.template<T>

    B.template<class T1,T2>

    C.template<class T1,class T2>

    D.template<class T1;class T2>


    正确答案:C

  • 第19题:

    下列的模板说明中,正确的是( )。A.template B.template C.template

    下列的模板说明中,正确的是( )。

    A.template <T1,T2>

    B.template <class T1,T2>

    C.template <class T1,class T2>

    D.template <typename T1;typename T2>


    正确答案:A
    解析:模板说明,要求每个参数前都有一个类型参数,多个参数需用逗号隔开。

  • 第20题:

    下列对模板的声明中正确的是A.templateB.templateC.template

    下列对模板的声明中正确的是

    A.template<T>

    B.template<class T1,T2>

    C.template<class T1,class T2>

    D.template<class T1;class T2>


    正确答案:C
    解析:本题考核模板的定义。模板定义的类型参数表>中包含一个或多个由逗号分隔的类型参数项,每一项由关键字class后跟一个用户命名的标识符,此标识符为类型参数,它不是一种数据类型,但可以同一般数据类型一样使用。在使用类模板时,必须将其实例化,即用实际的数据类型代替它。

  • 第21题:

    下列对模板的声明中,正确的是A.templateB.templateC.template

    下列对模板的声明中,正确的是

    A.template<T>

    B.template<class T1,T2>

    C.template<classT1,class T2>

    D.template<classT1;class T2>


    正确答案:C
    解析:本题考核模板的定义。模板定义的类型参数表>中包含一个或多个由逗号分隔的类型参数项,每一项由关键字class后跟一个用户命名的标识符,此标识符为类型参数,它不是一种数据类型,但可以同一般数据类型一样使用。在使用类模板时,必须将其实例化,即用实际的数据类型代替它。

  • 第22题:

    下面的程序段中,有()处错误。template T2 func(T1 a,b){return(a>b) ?(a) :(b) ;}A.

    下面的程序段中,有( )处错误。 template <class T1,T2> T2 func(T1 a,b) { return (a>b) ?(a) :(b) ; }

    A.1

    B.2

    C.3

    D.4


    正确答案:B
    解析:本题考核函数模板的定义。函数模板的一般说明形式如下:template类型形参表>返回类型函数名(形参表){//函数体}在C++中,如果一个模板声明列出了多个参数,则每个参数之间必须使用逗号隔开,每个参数都必须重复使用关键字class进行说明。由此可知:第1处错误:templateclassT1,T2>,T2前没有关键字class。第2处错误:func(T1a,B),变量b前没有类型说明。

  • 第23题:

    单选题
    在下列模板说明中,正确的是()
    A

    template〈typename T1,T2〉

    B

    template〈class T1,T2〉

    C

    template〈typename T1,typename T2〉

    D

    template(typedef T1,typedef T2)


    正确答案: B
    解析: 暂无解析