marios_auth
07-08-2004, 10:38 AM
For example i have the foo class
foo.h
class foo
{
public:
foo();
~foo();
void test_func();
double *get_mtx1 {return mtx;}
double **get_mtx2 {return mtx2;}
public:
double *mtx1;
double **mtx2;
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
foo.cpp
foo::foo()
{
int i;
mtx1=new double[10];
mtx2=new double*[10];
for (i=0;i<10;i++) {mtx2[i]=new double[10];}
}
I want to replace the vector mtx1 and matrix mtx2, with the
Vec_DP mtx1(10);
Mat_DP mtx2(10,10);
A)In the foo.h how must i change the
public:
double *mtx1;
double **mtx2;
I tried to do something like this
Vec_DP *mtx1_p;
Mat_DP **mtx2_p;
and allocate the in the constuctor foo.cpp
foo:foo()
{
mtx1_p = new Vec_DP(10);
mtx2_p = new Mat_DP(10,10);
}
But it doesnt't compile because of Mat_DP (something about can't convert *Mat_DP to **Mat_DP)
B)How can i modify the the two functions, get_mtx1 and get_mtx2 so to return the vector od matrix in somewhere else?
C)if i write
Vec_DP data(10);
Does is dynamically allocate the data, or i sould write like something like this
Vec_DP *data;
data=new Vec_DP(10);
How this works also for Mat_DP?
Thank You
foo.h
class foo
{
public:
foo();
~foo();
void test_func();
double *get_mtx1 {return mtx;}
double **get_mtx2 {return mtx2;}
public:
double *mtx1;
double **mtx2;
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
foo.cpp
foo::foo()
{
int i;
mtx1=new double[10];
mtx2=new double*[10];
for (i=0;i<10;i++) {mtx2[i]=new double[10];}
}
I want to replace the vector mtx1 and matrix mtx2, with the
Vec_DP mtx1(10);
Mat_DP mtx2(10,10);
A)In the foo.h how must i change the
public:
double *mtx1;
double **mtx2;
I tried to do something like this
Vec_DP *mtx1_p;
Mat_DP **mtx2_p;
and allocate the in the constuctor foo.cpp
foo:foo()
{
mtx1_p = new Vec_DP(10);
mtx2_p = new Mat_DP(10,10);
}
But it doesnt't compile because of Mat_DP (something about can't convert *Mat_DP to **Mat_DP)
B)How can i modify the the two functions, get_mtx1 and get_mtx2 so to return the vector od matrix in somewhere else?
C)if i write
Vec_DP data(10);
Does is dynamically allocate the data, or i sould write like something like this
Vec_DP *data;
data=new Vec_DP(10);
How this works also for Mat_DP?
Thank You