| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 373 人关注过本帖
标题:矩阵相加重载编译出错
只看楼主 加入收藏
cwl168
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2012-12-14
结帖率:8.33%
收藏
 问题点数:0 回复次数:2 
矩阵相加重载编译出错
#include<iostream>
using namespace std;
class M23
{
public:
    //M23 operator +(M23 &c2);
    friend M23 operator+(M23&,M23&);
    friend ostream& operator<<(ostream&,const M23&);
    friend istream& operator>>(istream&,const M23&);
private:
    int a[2][3];
};
ostream& operator<<(ostream& out,const M23& m)
{
     for(int i=0;i<2;i++)
     {
         for(int j=0;j<3;j++)
         {
             out<<m.a[i][j];
         }
         return out;

     }
}
istream& operator>>(istream& in,const M23& m)
{
   
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<3;j++)
            in>>m.a[i][j];
    }
    return in;
}
M23 operator+(M23& m1,M23& m2)
{
    M23 m;
    for(int i=0;i<2;++i)
        for(int j=0;j<3;++j)
            m.a[i][j] = m1.a[i][j] + m2.a[i][j];

    return m;
}
/*M23 M23::operator +(M23 &c2)
{
      
}*/
int main()
{
    M23 m1,m2,m3;
    cin>>m1>>m2;
    m3 = m1 + m2;
    cout<<m1<<endl<<m2<<endl<<m3<<endl;
    return 0;
}

--------------------Configuration: 10_4 - Win32 Debug--------------------
Compiling...
10_4.cpp
F:\Study Garden\上机内容\c++\10_4\10_4.cpp(7) : fatal error C1001: INTERNAL COMPILER ERROR
        (compiler file 'msc1.cpp', line 1786)
         Please choose the Technical Support command on the Visual C++
         Help menu, or open the Technical Support help file for more information
执行 cl.exe 时出错.

10_4.obj - 1 error(s), 0 warning(s)

搜索更多相关主题的帖子: public include private 矩阵 
2013-01-10 21:03
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
编译器本身葛屁了

不过,你对const根本不了解,不该用的地方用了,该用的地方不用
2013-01-11 09:47
马小柯
Rank: 2
等 级:论坛游民
帖 子:17
专家分:14
注 册:2013-4-10
收藏
得分:0 
你对const根本不了解,不该用的地方用了,该用的地方不用
#include<iostream>
 using namespace std;
 class M23
 {
 public:
     //M23 operator +(M23 &c2);
     friend M23 operator+(M23&,M23&);
     friend ostream& operator<<(ostream&, M23&);
     friend istream& operator>>(istream&, M23&);
 private:
     int a[2][3];
 };
 ostream& operator<<(ostream& out, M23& m)
 {
      for(int i=0;i<2;i++)
      {
          for(int j=0;j<3;j++)
          {
              out<<m.M23::a[i][j];
          }
          return out;
 
     }
 }
 istream& operator>>(istream& in, M23& m)
 {
     
    for(int i=0;i<2;i++)
     {
         for(int j=0;j<3;j++)
             in>>m.a[i][j];
     }
     return in;
 }
 M23 operator+(M23& m1,M23& m2)
 {
     M23 m;
     for(int i=0;i<2;++i)
         for(int j=0;j<3;++j)
             m.a[i][j] = m1.a[i][j] + m2.a[i][j];
 
    return m;
 }
 /*M23 M23::operator +(M23 &c2)
 {
      
 }*/
 int main()
 {
     M23 m1,m2,m3;
     cin>>m1>>m2;
     m3 = m1 + m2;
     cout<<m1<<endl<<m2<<endl<<m3<<endl;
     return 0;
 }
2013-04-18 17:50
快速回复:矩阵相加重载编译出错
数据加载中...
 
   



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

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