access object in array of pointers to dynamic array of class complex

Discussion in 'C++' started by jccorreu@gmail.com, May 20, 2006.

  1. Guest

    I'm taking in data from multiple files that represents complex numbers
    for charateristics of different elements. I begin with arrays of
    doubles and interpolate to get standard values in real and imaginary
    portions. To this end I have some dynamic arrays of doubles to hold
    the standardized individual rael and imaginary parts.

    double *ANreal, *ANimag, *BNreal, *BNimag, *CNreal, *CNimag;

    ANreal = new double[num];
    ANimag = new double[num];
    etc....

    Later I want to combine the seperate portions into the complex class.

    complex<double> *AN, *BN, *CN;

    AN = new complex<double>[count];
    etc...

    AN.real = ANreal[k];
    AN.imag = ANreal[k];
    etc...

    but this is not working. I get an error that forming
    apointer-to-member requires use the address-of operator (''.), and that
    "=" overloaded function as left operand. I do not want to use vectors,
    I want to do it using this paradigm so I can better learn its
    intricacies. When I use the -> operator in place of the .dot i am told
    that std::complex<double> does not have that overloaded member
    operator, and that left of ->real must point to class/struct. If I
    throw either a * or & out front I get illegal operaton on bound member
    function.

    Later I will use an array of pointers to these arrays of class objects

    complex<double> **BigN[4] = {*AN, *CN, *BN, *CN};

    so I can do the actual caclulations that this all builds up to, using a
    loop within a loop, so that I can go through the first element in each
    array in the order the arrays are listed in BigN, then go to the next
    element in each array in that order. Something like:

    for(int i = 0; i<count; i++)
    {
    for(int j = 0; j<3; j++)
    {
    result[j]=BigN[j] * BigN[j+1] etc...;
    }
    *AN++;
    *BN++;
    *CN++;
    }


    So the main question I have here is how to set the real and imaginary
    parts of the objects in the array of class complex<double>.

    thanks in advance
    James
     
    , May 20, 2006
    #1
    1. Advertising

  2. Re: access object in array of pointers to dynamic array of classcomplex

    * :
    >
    > complex<double> *AN, *BN, *CN;


    Tip 1: You'll get fewer problems with macros if you refrain from using
    all uppercase names for non-macros.

    Tip 2: You'll get fewer problems if you refrain from using globals.

    Tip 3: This is much much easier using std::vector.


    > AN = new complex<double>[count];
    > etc...
    >
    > AN.real = ANreal[k];
    > AN.imag = ANreal[k];
    > etc...
    >
    > but this is not working. I get an error that forming
    > apointer-to-member requires use the address-of operator (''.)


    'real' and 'imag' are not member variables, they're member functions
    (please do read the documentation).

    Try

    AN = std::complex( ANReal, ANImag );

    I'm assuming that using ANReal also for the imag part was a typo.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, May 20, 2006
    #2
    1. Advertising

  3. wrote:
    > I'm taking in data from multiple files that represents complex numbers
    > for charateristics of different elements. I begin with arrays of
    > doubles and interpolate to get standard values in real and imaginary
    > portions. To this end I have some dynamic arrays of doubles to hold
    > the standardized individual rael and imaginary parts.
    >
    > double *ANreal, *ANimag, *BNreal, *BNimag, *CNreal, *CNimag;
    >
    > ANreal = new double[num];
    > ANimag = new double[num];
    > etc....
    >
    > Later I want to combine the seperate portions into the complex class.
    >
    > complex<double> *AN, *BN, *CN;
    >
    > AN = new complex<double>[count];
    > etc...
    >
    > AN.real = ANreal[k];
    > AN.imag = ANreal[k];


    Both 'real' and 'imag' are the names of the member _functions_, not of data
    members. To set the real part (and the imaginary part) you need to
    construct
    a temporary 'complex' value and assign from it:

    AN = complex(ANreal[k], ANimag[n]);

    > etc...
    >
    > but this is not working. [..]


    Of course it isn't. Do you ever RTFM? I am sure it describes available
    interface for the 'complex' template.

    > So the main question I have here is how to set the real and imaginary
    > parts of the objects in the array of class complex<double>.


    See above.

    V
    --
    Please remove capital As from my address when replying by mail
     
    Victor Bazarov, May 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.amnet.net.au
    Replies:
    0
    Views:
    542
    news.amnet.net.au
    Apr 8, 2004
  2. news.amnet.net.au
    Replies:
    1
    Views:
    597
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  3. Replies:
    9
    Views:
    586
    justanotherguy
    Dec 3, 2004
  4. Replies:
    5
    Views:
    449
    James Kanze
    Jun 27, 2008
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    714
Loading...

Share This Page