Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

function calling in c++

Name: Anonymous 2007-01-10 20:23

I'm kinda new to c++, and I have a question that I can't really define well enough for google to give me answers.

basically, what i want to do is loop through a list of classes that i know have a specific function and call it. I've tried something like
   *(ObjectArray[0] + loop).function();
where ObjectArray would be an string array that holds all of the function names. This fails, because function() is not defined, even though I've declared it in the class.

Any ideas?

Name: Anonymous 2007-01-10 21:24


class SampleClass;
class SampleClass2 : public SampleClass { ... };
class SampleClass3 : public SampleClass { ... };

SampleClass* Array[2];
Array[0] = new SampleClass2;
Array[1] = new SampleClass3;

for(int i=0;i<2;i++) Array[i].function();


Note that the array is an array of base class pointers, and the other classes inherit from the base class.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List