469,330 Members | 1,229 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

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

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[i].real = ANreal[k];
AN[i].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 '06 #1
2 2709
* jc******@gmail.com:

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[i].real = ANreal[k];
AN[i].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[i] = std::complex( ANReal[i], ANImag[i] );

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?
May 20 '06 #2
jc******@gmail.com 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[i].real = ANreal[k];
AN[i].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[i] = 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
May 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Gerald | last post: by
3 posts views Thread by Jack Addington | last post: by
3 posts views Thread by tomerdr | last post: by
13 posts views Thread by WaterWalk | last post: by
reply views Thread by Purva khokhar | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.