博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用vector实现矩阵, vector传参必须用模板泛型
阅读量:7015 次
发布时间:2019-06-28

本文共 965 字,大约阅读时间需要 3 分钟。

#pragma once#include "stdafx.h"//用vector实现矩阵, vector传参必须用模板泛型template 
class Matrix {private: //2维的矩阵,2维的vector数组,vector就是一种动态数组 vector
> array;public: //constructor(), 填充数组(行数) Matrix(int rows, int cols) :array(rows) { for (int i = 0; i < rows; i++) //resize(),改变当前使用数据的大小,如果它比当前使用的大,者填充默认值 array[i].resize(cols); } //重载操作符[],实现索引器,常量引用传值 const vector& operator[](int row)const { return array[row]; } //重载操作符[],实现索引器,变量引用传值 vector & operator[](int row) { return array[row]; } //Length() int numrows() const { //array.Length() return array.size(); } //numcols() int numcols() const { //numrows() is true; return numrows() ? array[0].size() : 0; } //deconstructor() virtual ~Matrix() {} //copy() void copy(const Matrix
& from, Matrix
& to) { for (int i = 0; i < to.numrows; i++) { to[i] = from[i]; } }};

  

转载于:https://www.cnblogs.com/blacop/p/6602674.html

你可能感兴趣的文章