Your error codes don't mean much as they are not standardized across compilers. It is better to post the text of the errors.
This is wrong:
Code:
unsigned int row;
unsigned int column;
double TDvect[row][column];
public:
TDVect(unsigned int A, unsigned int B) {
row = A;
column = B;
}
Array dimensions in C++ must be constants, so you can't use row and column like that (and in particular you can't set them at instantiation time and expect their values to automatically (re)size the arrays). Instead, you need to dynamically allocate the memory, so TDvect should be a pointer. It's usually easiest to allocate it as a one-dimensional array and simulate access as a two-d array. BTW, a two-d vector is usually called a matrix.
Code:
#include <iostream>
using namespace std;
class Matrix {
private:
unsigned rows_, cols_;
double* mat_;
public:
Matrix(unsigned r, unsigned c)
: rows_(r), cols_(c), mat_(new double[r * c])
{}
~Matrix() {
delete[] mat_;
}
unsigned rows() const {
return rows_;
}
unsigned cols() const {
return cols_;
}
double get(unsigned r, unsigned c) const {
return mat_[r * cols_ + c];
}
void set(unsigned r, unsigned c, double x) {
mat_[r * cols_ + c] = x;
}
};
int main() {
Matrix a(4, 6);
cout << a.rows() << ", " << a.cols() << "\n";
a.set(2, 3, 42);
cout << a.get(2, 3) << "\n";
return 0;
}
You could use an underlying std::vector instead of explicit dynamic allocation.
Code:
#include <iostream>
#include <vector>
using namespace std;
class Matrix {
private:
vector<double> mat_;
unsigned cols_;
public:
Matrix(unsigned r, unsigned c)
: mat_(r * c), cols_(c)
{}
unsigned rows() const {
return mat_.size() / cols_;
}
unsigned cols() const {
return cols_;
}
double get(unsigned r, unsigned c) const {
return mat_[r * cols_ + c];
}
void set(unsigned r, unsigned c, double x) {
mat_[r * cols_ + c] = x;
}
};
int main() {
Matrix a(4, 6);
cout << a.rows() << ", " << a.cols() << "\n";
a.set(2, 3, 42);
cout << a.get(2, 3) << "\n";
return 0;
}