arrays of function calls and memory errors

Sassy Rabbit

Member
Sep 7, 2007
89
0
0
I am having a run time error that I can't relate to a mistake in the algorithm and seem to be reminiscent of a memory error.

The object has an array of function calls which are initialized during runtime. The functions are then called with the following syntax: (this->*kCalls[tj][ti])( function input ). Now some of my functions are set to null at runtime because they refer to cases not present in the current state of my program - would this cause a problem?

Thanks!
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,674
146
106
www.neftastic.com
Null functions pointers shouldn't matter as long as you don't try to call them. Take the dereference off the array... the array operators are already dereferencing for you - that might help.
 

Templeton

Senior member
Oct 9, 1999
467
0
0
Originally posted by: SunnyD
Null functions pointers shouldn't matter as long as you don't try to call them. Take the dereference off the array... the array operators are already dereferencing for you - that might help.

He's not dereferencing the array, ->* is the pointer to member operator.

That said, you should only be calling through to valid function pointers, anything else is undefined and will probably lead to strange runtime behavior.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
If you suspect memory issues, I strongly recommend running your program under Valgrind (I don't think Valgrind runs under Windows, but it's really really useful).