代码可以正常工作,但是我想我还缺少其他实现的东西,只是我不知道要实现什么。请提出一些建议。
大概功效?
实现以下实现:
//功能
调整大小resize()
分配assign()
访问access()
移动move()
找到get_pos()
复制到2D向量copy()
复制到一维向量copy()
//操作员
插入<<< br /> 摘录>>
等同=
// matrix.h
#pragma once
#include <iostream>
#include <cstring>
#include <vector>
#include "dimensional_size.h"
using namespace std;
#define _MATRIX_H_
template<typename type, size_t _breadth = 0, size_t _height = 0, size_t _width = 0>
class matrix {
public:
matrix();
~matrix();
void resize(size_t new_breadth, size_t new_height = 0, size_t new_width = 0);
void assign(type obj, pos z, pos y, pos x);
type access(pos z=0, pos y = 0, pos x = 0);
void move(dimensional_pos<type> old_pos, dimensional_pos<type> new_pos);
size_t get_capacity();
vector<vector<type> >& copy(vector<vector<type> > dest, pos z = 0, pos y = 0, pos dest_z = 0);
vector<type>& copy(vector<type> dest, pos z = 0, pos y = 0);
dimensional_pos<type> get_loc(type& t);
void operator<<(type t);
void operator>>(type t);
matrix<type, _breadth, _width, _height> operator=(matrix<type, _breadth, _height, _width> obj);
private:
dimensional_size<_breadth, _height, _width> size_obj;
vector<vector<vector<type> > > dat;
};
// Dimension_size.h
Dimension_size.h提供数据结构“ Dimension_size”和类“ Dimension_pos”,其类型定义为“ pos”,为无符号长整型
#pragma once
#include <iostream>
#include <stdarg.h>
#include <vector>
#define _DIMENSIONAL_SIZE_H_
using namespace std;
template<size_t z, size_t y, size_t x>
struct dimensional_size {
dimensional_size();
~dimensional_size();
size_t get_capacity();
size_t get_breadth();
size_t get_height();
size_t get_width();
void up_size(size_t z = 0, size_t y = 0, size_t x = 0);
private:
size_t absolute_x;
size_t absolute_y;
size_t absolute_z;
};
template<typename type>
class dimensional_pos {
public:
dimensional_pos();
dimensional_pos(pos z = 0, pos y = 0, pos x = 0);
~dimensional_pos();
dimensional_pos& get_pos(vector<type> stream, type& t);
dimensional_pos& get_pos(vector<vector<type> > stream, type& t);
dimensional_pos& get_pos(vector<vector<vector<type> > > stream, type& t);
pos get_z();
pos get_y();
pos get_z();
private:
pos absolute_x;
pos absolute_y;
pos absolute_z;
};
通过矢量缩放以找到类型的对象的示例样式
template<typename type>
dimensional_pos<type>& dimensional_pos<type>::get_pos(vector<vector<vector<type> > > stream, type& t) {
dimensional_pos<type> obj;
for (pos i = 0; i < stream.size(); i++) {
for (pos j = 0; j < stream[i].size(); j++) {
for (pos k = 0; k < stream[i][j].size(); k++) {
if (t == stream[i][j][k]) {
obj(i, j, k);
return obj;
}
}
}
}
}
没有任何错误。