Array of classes, call function in all

Dec 17, 2012 at 7:14pm
Hi,

I have an array of classes. For arguments sake, we will say they are:

MyClass EachClass[100];

Therefore creating 100 instances of class 'MyClass' called EachClass[x].
MyClass has function SetVal(int MyVal);

How can I call this function in all classes? I know I could use a loop, but surely there's a one line solution to this? like EachClass[all].SetVal(12345);
Dec 17, 2012 at 7:41pm
You can use the ctor

1
2
 
MyClass EachClass[100] = MyClass(some_value); 


provided you have ctor

1
2
 
MyClass(int value);
Topic archived. No new replies allowed.