1.int Func(int,int);不可与下列哪个函数构成重载( )
A.int Func(int,int,int); B.double Func(int,int);C.double Func(double,double); D.double Func(int,double);答案:B
参数类型,数目不同,可以构成重载,返回类型不同不能构成重载。
main函数不能重载。
注意:顶层const不影响传入函数的对象。一个拥有顶层const的形参无法和另一个没有顶层const的形参区分开来:
Record lookup(Phone);
Record lookup(const Phone); //重复声明了Record lookup(Phone)
Record lookup(Phone*);
Record lookup(Phone* const); //重复声明了Record lookup(Phone*)
如果形参是某种指针或引用,则通过区分其指向的是常量对象还是非常量对象可以实现函数重载,此时const是底层的。
Record lookup(Account&); //函数作用于Account的引用
Record lookup(const Account&); //新函数,作用于常量引用
Record lookup(Account*); //新函数,作用于指向Account的指针
Record lookup(const Account*); //新函数,作用于指向常量的指针