矩阵模板,右元函数重载<<操作符
2015-04-07 13:58
225 查看
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;
}
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;
}
相关文章推荐
- poj 3070 <矩阵快速幂【模板】求Fibonacci数列>
- 【模板小程序】循环方阵构造(仿《剑指offer》循环矩阵打印)
- web.xml <-> web-fragment.xml (Servlet 2.3, 2.4, 2.5 + 3.0)模板
- 矩阵快速幂模板
- 矩阵快速幂 模板
- 关于c++中模板 T 无法限制的替代方案template< T extends Base>
- 洛谷P3390 【模板】矩阵快速幂
- HDU 1757 A Simple Math Problem (矩阵快速幂模板)
- 用线段树求解坐标矩阵中的交并集面积思路及其模板代码
- <模板><计算几何>凸包-旋转卡壳最小面积外接矩形
- 求斐波那契数列的多种方法(有矩阵(附好模板))
- 一些学习到的矩阵运算的模板(T_T)
- 一道坑题,用来更新矩阵模板,WIKI OI 1281
- 类模板 Mat_<float> sal
- perl高级排序,<=>操作符,飞船操作符
- PostgreSQL学习手册(函数和操作符<二>)
- javascript 操作符(~、&、|、^、<<、>>)使用案例
- 两步学会C++模板的使用<1>
- [原]Unity手游之路<四>3d旋转-四元数,欧拉角和变幻矩阵
- BZOJ 2462: [BeiJing2011]矩阵模板