twinkle_snow 2016-04-08 08:38 采纳率: 76.5%
浏览 1471

关于C++ 中&运算符的问题

#include<iostream>
#ifndef STRNGBAD H
#define STRNGBAD H
class StringBad
{
private:
    char *str;
    int len;
    static int num_strings;
public:
    StringBad(char *str);  //constructor
    StringBad();           //default constructor
    ~StringBad();
    friend std::ostream & operator <<(std::ostream & os , const StringBad & st);
};
#endif

求大神解释一下这一句:
friend std::ostream & operator <<(std::ostream & os , const StringBad & st);
那个&运算符是什么意思?以及括号中的参量?

  • 写回答

3条回答 默认 最新

  • shallies 2016-04-08 08:49
    关注

    在C++里面,&可以表示对变量的引用,作用有点像指针。比如:
    int iVal;
    int* pIVal=&iVal; //pIVal指向iVal
    int& iVal2=iVal; //iVal2等同于 iVal
    iVal=123;
    printf("*pIVal=%d, iVal2=%d", *pIVal, iVal2); //输出结果: *pIVal=123, iVal2=123

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站