00000

01010

class base { public: int bval; base(){ bval=0;} }; class deri:public base { public: int dval; deri(){ dval=1;} }; void SomeFunc(base *arr,int size) { for(int i=0; i‹size; i++,arr++) cout«arr-›bval; cout«endl; } int main() { base BaseArr[5]; SomeFunc(BaseArr,5); deri DeriArr[5]; SomeFunc(DeriArr,5); }

the explication for this can be found here: http://technical-int..._answer_25.aspx

So I modified the function so that it will output me:

00000

00000

like this:

void SomeFunc(base *arr,int size, int o) { int k=1; if (o==2) k=sizeof(deri)/sizeof(base); //works only for perfect div for(int i=0; i<size; i++) { cout<<arr->bval; arr+=k; } cout<<endl; } int main() { base BaseArr[5]; SomeFunc(BaseArr,5,1); deri DeriArr[5]; SomeFunc(DeriArr,5,2); }

but I'm wondering if is there a better way to do it, using the same original function?

Thanks!