Hi,
I like to use to use c++Builder 6.0 a Dynamic Array struct to hold a multidimensional array of float.
I tried following code:
/* Code
typedef DynamicArray< DynamicArray < float > > T2DStringArray;
T2DStringArray* p2DStringArray;
p2DStringArray = new T2DStringArray;
p2DStringArray->set_length(10);
for (int i=0; iLength; i++){
p2DStringArray[i].set_length(i+1);
for (int j=0; j::operator =(float)'
How can access to the array data?
I also tried this way for acces to data:
p2DStringArray[i].[j] = (float)(0.5*i*10+j);
But I take this error:
E2280 Member identifier expected
Someone can help me?
Thanks,
Giorgio.
Comments
:
: I like to use to use c++Builder 6.0 a Dynamic Array struct to hold a
: multidimensional array of float.
: I tried following code:
:
: /* Code
:
: typedef DynamicArray< DynamicArray < float > > T2DStringArray;
:
: T2DStringArray* p2DStringArray;
: p2DStringArray = new T2DStringArray;
: p2DStringArray->set_length(10);
:
: for (int i=0; iLength; i++){
: p2DStringArray[i].set_length(i+1);
:
: for (int j=0; j::operator =(float)'
:
: How can access to the array data?
:
: I also tried this way for acces to data:
: p2DStringArray[i].[j] = (float)(0.5*i*10+j);
:
: But I take this error:
: E2280 Member identifier expected
:
: Someone can help me?
:
: Thanks,
: Giorgio.
:
The index operator does not work the same when you use pointers: you'll have to use the full notation.
See the code below how terrible it looks like (and exception unsafe!).
[code]
typedef DynamicArray< DynamicArray < double > > T2DStringArray;
T2DStringArray* p2DStringArray = new T2DStringArray;
p2DStringArray->set_length(10);
for (int i=0; iLength; ++i)
{
p2DStringArray->operator [](i).set_length(i+1);
for (int j=0; joperator[](i).Length; ++j)
{
p2DStringArray->operator [](i)[j] = 0.5;
}
}
[/code]
Why not use the STL std::vector? Check out the code below. It has many advantages.
[code]
#include
std::vector< std::vector < double > > v;
v.resize(10);
for (int i=0; i!= v.size(); ++i)
{
v[i].resize(i+1);
for (int j=0; j!= v[i].size(); ++j)
{
v[i][j] = 0.5;
}
}
[/code]
See ya,
bilderbikkel