重载运算符“ <<” 和“>>” 运算符


 

  • :“ <<  ”   "  >>  " 的重载作为友元函数重载,有两种方法:1,把变量作为public,就可以不用友元声明;2,先友元声明。
  • :在进行友元声明的时候,要加上‘    ;’
     1 Array{
     2     pubilc:
     3     friend istream &operate>>( istream &is , Array &a);
     4 };
     5 istream operate>>( istream &is , Array &a)
     6 {
     7     is >> a;
     8    return is
     9 }
    10 
    11 
    12 
    13 
    14 Array{
    15     public:
    16     friend ostream &operate<<( ostream &is , Array &a);
    17 };
    18 istream operate>>( istream &is , Array &a)
    19 {
    20     os<< a;
    21  return os;
    22 }

     

    http://cise.sdust.edu.cn/OJ/problem.php?cid=3183&pid=1



 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM