Dynamic Array - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Dynamic Array

ma.giorgioma.giorgio Posts: 1Member
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

  • bilderbikkelbilderbikkel Posts: 754Member
    : 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.
    :
    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
Sign In or Register to comment.