在函数前加个&是什么意思
1.定义函数的时候在函数前加个&引用符号是什么意思,是说这个函数是引用型的吗?但那又是什么意思,请大家举例说明.
2.还有 explicit 定义的是一种什么类型,请举例说明。
3.ostream & operator < <(ostream &out,const Rectangle &rhs){}
请大家给我分析下这个函数是怎么弄的,ostream是什么类型的,加个&是什么意思,operator < <在这里是运算符的重载吗?怎么看起来不太像啊
[解决办法]
#include <iostream.h>
class Rectangle
{
int width,hight;
friend ostream & operator < <(ostream &out,const Rectangle &rhs)
{ out < < "[ " < <rhs.width < < ", " < <rhs.hight < < "] "; return out;}
public: Rectangle(int _w, int _h):width(_w),hight(_h){}
};
void main()
{
Rectangle rta(10,20), rtb(32,56);
cout < <rta < <rtb < <endl; //只有返回引用,这句才能正确执行!
}