1 Which of the following options are returned by the typeid operator in C++? (C++里面的typeid运算符返回值是什么) A. A reference to a std::type_info object (type_info对象的引用) B. A const reference to a const std::type_info object (type_info常量对象的常量引用) C. A const std::type_info object (type_info常量对象) D. A reference to a const std::type_info object (type_info常量对象的引用) E. A const reference to a std::type_info object (type_info对象的常量引用)
2 Which of the following statements accurately describe unary operator overloading in C++? (一元运算符重载,下列说法正确的是:) A. A unary operator can be overloaded with no parameters when the operator function is a class member. (当运算符函数是一个类成员时,一元运算符能被无参形式重载) B. A unary operator can be overloaded with one parameter when the operator function is a class member. (当运算符函数是一个类成员时,一元运算符能被带一个参数形式重载) C. A unary operator can be overloaded with one parameter when the operator function is free standing function (not a class member). (当运算符函数是一个独立函数时,一元运算符能被带一个参数形式重载) D. A unary operator can only be overloaded if the operator function is a class member. (当且仅当运算符函数是一个类成员时,一元运算符才会被重载) E. A unary operator can only be overloaded with no parameters when the operator function is a free standing function. (当且仅当运算符函数是一个独立函数时,一元运算符才会被重载)
11.2 语法 定义一个重载运算符就像定义一个函数,只是该函数的名字是o p e r a t o r @,这里@代表运 算符。函数参数表中参数的个数取决于两个因素: 1) 运算符是一元的(一个参数)还是二元的(两个参数)。 2) 运算符被定义为全局函数(对于一元是一个参数,对于二元是两个参数)还是成员函数 (对于一元没有参数,对于二元是一个参数— 对象变为左侧参数)。
我也不好怎么说你,你看看c++ 标准如何? 13.5.1 Unary operators [over.unary] 1 A prefix unary operator shall be implemented by a non-static member function (9.3) with no parameters or a non-member function with one parameter. Thus, for any prefix unary operator @, @x can be interpreted as either x.operator@() or operator@(x). If both forms of the operator function have been declared, the rules in 13.3.1.2 determine which, if any, interpretation is used. See 13.5.7 for an explanation of the postfix unary operators ++ and --. 2 The unary and binary forms of the same operator are considered to have the same name. [Note: consequently, a unary operator can hide a binary operator from an enclosing scope, and vice versa. ] 13.5.2 Binary operators [over.binary] 1 A binary operator shall be implemented either by a non-static member function (9.3) with one parameter or by a non-member function with two parameters. Thus, for any binary operator @, x@y can be interpreted as either x.operator@(y) or operator@(x,y). If both forms of the operator function have been declared, the rules in 13.3.1.2 determines which, if any, interpretation is used.
这个是二元操作符的定义:
A binary operator shall be implemented either by a non-static member function (9.3) with one parameter or by a non-member function with two parameters.