矩阵模板,右元函数重载<<操作符

1.矩阵元素类型,以及矩阵的宽高都声明为模板参数
2.双元操作符一般都重载为友元函数
   cout << matrix  :可以看成左操作符是输出流对象,右操作符时矩阵对象
   string < string :它的友元函数声明为
   friend bool operator > (const string& string1, const string& string2)
   
template <class T, unsigned int R, unsigned int C>
class MTVariable
{
public:
    union {
        T m[R][C];
    };

    inline unsigned int rsize(void) const
    {
        return R;
    }

    inline unsigned int csize(void) const
    {
        return C;
    }

    friend std::ostream& operator <<(std::ostream& os, const MTVariable<T, R, C>& v)
    {
        os << '[';
        unsigned int c, r;
        for (r = 0; r < R; ++r)
        {
            os.width(2);
            for (c = 0; c < C-1; ++c)
            {
                os << v.m[r][c] << " ";
            }
            os << v.m[r][c] << ';';
        }
        os << ']';
        return os;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值