[英]operator overloading in matrices: how to overload () and = at the same time
我正在嘗試制作一類矩陣並嘗試像這樣在該索引處分配值
M(0,3)=3;
通過運算符重載。 無法弄清楚如何重載此運算符,其原型應為這樣?
void operator()=(int i,int j,int s);//how to overload?
float operator()(int i,int j);//this can be used to get that number form that index.
沒有operator()=
。 您希望您的operator()
返回對矩陣中元素的引用。 然后,您可以分配給所引用的元素。
float& operator()(int i,int j);
const float& operator()(int i, int j) const;
您可能還需要const
重載,它返回const引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.