X
xontrn
I get the error:
"error C2664: 'C<T>::C(T **,int,int)' : cannot convert parameter 1
from 'float [2][3]' to 'float **'"
An array of array does not get resolved to a pointer-to-pointer?
#include <iostream>
using namespace std;
template<typename T>
class C
{
public:
C(T** d, int m, int n)
{
mData = new T*[m];
for(int i = 0; i < m; ++i)
mData = new T[n];
for(int i = 0; i < r; ++i)
for(int j = 0; j < c; ++j)
mData[j] = d[j];
r = m;
c = n;
}
~C()
{
for(int i = 0; i < r; ++i)
delete[] mData;
delete[] mData;
}
T& operator()(int i, int j)
{
return mData[j];
}
void print()
{
for(int i = 0; i < r; ++i)
{
for(int j = 0; j < c; ++j)
{
cout << data[j] << "\t";
}
cout << endl;
}
}
private:
T** data;
int r;
int c;
};
int main()
{
float m[2][3];
m[0][0] = 1.0f;
m[0][1] = 2.0f;
m[0][2] = 3.0f;
m[1][0] = 4.0f;
m[1][1] = 5.0f;
m[1][2] = 6.0f;
m[2][0] = 7.0f;
m[2][1] = 8.0f;
m[2][2] = 9.0f;
C<float> T(m, 2, 3);
T.print();
}
"error C2664: 'C<T>::C(T **,int,int)' : cannot convert parameter 1
from 'float [2][3]' to 'float **'"
An array of array does not get resolved to a pointer-to-pointer?
#include <iostream>
using namespace std;
template<typename T>
class C
{
public:
C(T** d, int m, int n)
{
mData = new T*[m];
for(int i = 0; i < m; ++i)
mData = new T[n];
for(int i = 0; i < r; ++i)
for(int j = 0; j < c; ++j)
mData[j] = d[j];
r = m;
c = n;
}
~C()
{
for(int i = 0; i < r; ++i)
delete[] mData;
delete[] mData;
}
T& operator()(int i, int j)
{
return mData[j];
}
void print()
{
for(int i = 0; i < r; ++i)
{
for(int j = 0; j < c; ++j)
{
cout << data[j] << "\t";
}
cout << endl;
}
}
private:
T** data;
int r;
int c;
};
int main()
{
float m[2][3];
m[0][0] = 1.0f;
m[0][1] = 2.0f;
m[0][2] = 3.0f;
m[1][0] = 4.0f;
m[1][1] = 5.0f;
m[1][2] = 6.0f;
m[2][0] = 7.0f;
m[2][1] = 8.0f;
m[2][2] = 9.0f;
C<float> T(m, 2, 3);
T.print();
}