标题:sifangli1@126.com
取消只看楼主
sifangli
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-11-11
 问题点数:0 回复次数:0 
sifangli1@126.com
请高手帮个忙  下面的程序为什么运行不了?我的是vc++6.0  
改了第一二行为#include<iosteam.h>也不行
#include<iostream>
using namespace std;
class M
{public:
  M();
  friend operator+(M &,M &);
  friend ostream& operator<<(ostream&,M&);
  friend istream& operator>>(istream&,M&);
private:
    int mat[2][3];
};
M::M()
{for(int i=0;i<2;i++)
 for(int j=0;j<3;j++)
     mat[i][j]=0;
}
M operator+(M&a,M&b)
{M c;
for(int i=0;i<2;i++)
  for(int j=0;j<3;j++)
  {
    c.mat[i][j]=a.[i][j]+b.[i][j];
  }
return c;
}
istream& operator>>(istream &in,M &m)
{cout<<"input valu of matrix &m"<<endl;
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
in>>m.mat[i][j];
return in;
}

 ostream& operator<<(ostream&out,M&m)
 {for(int i=0;i<2;i++)
 for(int j=0;j<3;j++)
 {
     out<<m.mat[i][j]<<" ";
     out<<endl;
 }
 return out;
 }

 int main()
 {M a,b,c;
 cin>>a;
 cin>>b;
 cout<<endl<<"M.a:"<<endl<<a<<endl;
 cout<<endl<<:M.b:"<<endl<<b<<endl;
 c=a+b;
 cout<<endl<<"M c=M a+M b:"<<endl<<c<<endl;
 return 0;
 }
搜索更多相关主题的帖子: private 
2008-11-11 13:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-243618-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.154044 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved