看板Programming
标 题[问题] C++ 矩阵输入值在做完+法*法後被改了
发信站交大资讯次世代BS2 (Mon Oct 12 00:08:43 2009)
转信站ptt!news.ntu!ctu-gate!ctu-peer!news.nctu!csnews.cs.nctu!news.cs.nctu!B
写了个矩阵相加相乘的class
假设输入a,b两矩阵
在做完a+b或a*b时
a的值就被改掉
cout<<a;
answer=(a+b);
cout<<a;
前後出来的a不同
接着去看operator+
在return前 cout<<*this; 出来看
cout<<*this;
return answer;
this没被变动
後来又去看了operator=
SparseMatrix& SparseMatrix::operator=(const SparseMatrix& rhs)
在return之前把*this跟rhs cout出来看
cout<<*this<<endl<<rhs;
return *this;
都没有错
那a到底在哪里被改到??
恳请板上的大大为小弟解惑
感谢
--
※ Origin: 交大次世代(bs2.to)
◆ From: sky.Dorm13.NCTU.edu.tw