Object Arrays and Inheritance
I'm quite new to programming but I've looked all over the web and cant find anything that answers my question, so now I'm trying this, hope you can help! :rolleyes:
So, I'm trying to create a class that has many variables and many functions to access them, plus a few more to use the data. I made this test program to see whether I had the object oriented concepts down. Apparently, I dont. I've gotten the object array to work, but the most important part doesn't work. That is, when I use parentobject->function() the function only gets called to the parent object and not all its children, which is what I want. Is there some TObjArray library or other way of doing this that would be easier. I'm trying to avoid using a for loop every time I want to call a function to each child object (that would slow things down greatly). I'd like to be able to call uniform functions to each object with one line of code. Here's an example of what I'm working with. Thanks in advance for any help. :)
const int TOTAL=40;
class TDot
{
public:
void SetCapacity(int StartCapacity);
void SoundOff();
TDot* D[TOTAL];
int Capacity;
//and stuff
private:
//more stuff
}
#include<stuff>
int NumStartDots=10,StartCapacity=40,wait;
TDot *Population = new TDot;
void main(void)
{
for (int i=0;i<NumStartDots;i++)
{
Population->D[i] = new TDot;
Population->D[i]->SetCapacity(StartCapacity);
}
Population->SoundOff();
cin>>wait;
}
void TDot::SetCapacity(int StartCapacity)
{
Capacity=StartCapacity;
}
void TDot::SoundOff()
{
cout<<Capacity<<endl;
}
-AceHigh