【发布时间】:2015-01-02 14:53:18
【问题描述】:
我正在构建一种能够管理矩阵的类型,所以我已经搜索了如何制作 [][] 运算符,但没有运气,所以知道如何做到这一点,我只需要一种制作双运算符的方法 这是正在建设的班级
#include<iostream>
#include<conio.h>
using namespace std;
class ddouble{
private:
unsigned short int x, y;
public:
ddouble();
ddouble(unsigned short int, unsigned short int);
double **M;
void read();
void print();
};
ddouble::ddouble(unsigned short int m, unsigned short int n){
for (int i = 0; i < m; i++){
M = new (nothrow) double *[i];
for (int I = 0; I < n; I++){
M[i] = new (nothrow) double[I];
}
}
}
void ddouble::read(){
for (int i = 0; i < x; i++){
cout << "plz enter line \n";
for (int I = 0; I < y; I++){
cin >> M[i][I];
}
}
}
void ddouble::print(){
cout << "i,j\t|\t";
for (int i = 0; i < y; i++){
cout << i << "\t";
}
cout << endl;
for (int i = 0; i < x; i++){
cout << i << "\t|\t";
for (int I = 0; I < y; I++){
cout << M[i][I] << "\t";
}
cout << endl;
}
}
void main(){
ddouble a(2, 2);
a.read();
a.print();
_getch();
}
【问题讨论】:
-
你不能。写一个
operator[],它返回的东西也有一个operator[]。 -
我会尝试使用它,Obvlious 上尉并报告
标签: c++