P
pauldepstein
Suppose I have a class of objects which take an integer parameter.
I can easily create an object with the required parameter as follows:
name_of_class variable_name(integer_value);
For clarity, suppose I have a bank-account class and each object falls
into one of 5 distinct categories.
Then I might have code like:
bank_account object_1(5);
bank account object_2(3);
But if I have lots of objects of the class, I don't know what the
correct syntax is for doing such assignments (creating the objects) in
a loop.
Would the following work? (By using a giant leap of imagination, let
my_integer_valued_function denote an integer_valued function.)
object_array = new bank_account[n];
for (i=0; i<n; i++)
bank_account object_array (my_integer_valued function of i);
Or perhaps it should be
object_array = new bank_account[n];
for (i=0; i<n; i++)
object_array (my_integer_valued function of i);
Thanks for all your help and advice. I have received a lot of help
from this group.
Paul Epstein
I can easily create an object with the required parameter as follows:
name_of_class variable_name(integer_value);
For clarity, suppose I have a bank-account class and each object falls
into one of 5 distinct categories.
Then I might have code like:
bank_account object_1(5);
bank account object_2(3);
But if I have lots of objects of the class, I don't know what the
correct syntax is for doing such assignments (creating the objects) in
a loop.
Would the following work? (By using a giant leap of imagination, let
my_integer_valued_function denote an integer_valued function.)
object_array = new bank_account[n];
for (i=0; i<n; i++)
bank_account object_array (my_integer_valued function of i);
Or perhaps it should be
object_array = new bank_account[n];
for (i=0; i<n; i++)
object_array (my_integer_valued function of i);
Thanks for all your help and advice. I have received a lot of help
from this group.
Paul Epstein