473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2903
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
8
by: Gerald | last post by:
I have a problem with an array of pointers. In a program I'm writing, I have to read a file, containing thousands of short lines. The content of another file will be compared against each line...
3
by: Jack Addington | last post by:
Quite new to C# but I am getting quite confused with Array's and ArrayLists. This is probably the same old iteration of a basic question but I can't seem to find a clear answer/example of this...
1
by: lemonade | last post by:
Hello! Can someone explain to me the difference between dynamic array of pointers vs dynamic array of objects by giving a real life example. Following is the code that I am using for dynamic...
3
by: tomerdr | last post by:
Hi, I have been asked to create a dynamic template array as an exercise. the array should be used as follows: CDynamicArray<City*arr; or CDynamicArray<Streetarr; It also need to support...
12
by: subramanian100in | last post by:
Suppose class Base { public: virtual ~Test() { ... } // ... }; class Derived : public Base
13
by: WaterWalk | last post by:
Hello. When I consult the ISO C++ standard, I notice that in paragraph 3.6.2.1, the standard states: "Objects with static storage duration shall be zero-initialized before any other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.