The class defines objects that are DIMXDIM dynamic two-dimensional arrays that contain objects of any type. Ive added c'tor, d'tor, operator =, operator () that allows me to get the value of (2,5) column/row. and a main that demonstrates the action of T from type float and complex.
I have tried to change the declaration of the c'tor but i think it is not the issue. im really lost
#include<iostream>
#include<cassert>
using namespace std;
//#define DIM 3
template<class T, int DIM>
class Array {
T **p;
public:
template<class T, int DIM>
class Array(T** p) {
p = new T*[DIM];
assert(p != NULL);
for (int i = 0; i < DIM; i++)
{
p[i] = new T[DIM];
assert(p[i] != NULL);
}
for (int i = 0; i < DIM; i++) {
for (int j = 0; j < DIM; j++) {
p[i][j] = 3;
}
}
}
template<class T, int DIM>
class ~Array() {
for (int i = 0; i < DIM; i++) {
delete[]p[i];
}
delete[]p;
}
template<class T, int DIM>
Array& operator=(const Array& other) {
if (this != other) {
for (int i = 0; i < DIM; i++) {
delete[]p[i];
}
delete[]p;
this.p = new T*[DIM];
assert(p != NULL);
for (int i = 0; i < DIM; i++)
{
p[i] = new T[DIM];
assert(p[i] != NULL);
}
for (int i = 0; i < DIM; i++) {
for (int j = 0; j < DIM; j++) {
p[i][j] = other.p[i][j];
}
}
}
}
};
int main() {
Array<int, 3> ob[][];
return 0;
}
E0065 expected a ';' Project C:\Users\Lorine E0070 incomplete type is not allowed Project
E0098 an array may not have elements of this type
C2988 unrecognizable template declaration/definition
C2059 syntax error: 'type'
C2334 unexpected token(s) preceding '{'; skipping apparent function body C2332 'class': missing tag name
C3306 '': unnamed class template is not allowed
C2988 unrecognizable template declaration/definition
C2143 syntax error: missing ';' before '~'