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

J

jccorreu

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
 
A

Alf P. Steinbach

* (e-mail address removed):
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.
 
V

Victor Bazarov

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top