1,075,657 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Posts by KenJackson which have been Voted Up

Of course you can. Declare the array parameter as a pointer to void, add a parameter that tells the function what the type is, use the type parameter in a switch statement or if-then-elses, and cast the array parameter appropriately in each case.

The afforementioned qsort function is only slight twist on this in that it requires a function parameter that works for only one type, so the case statement and casting is obviated.

Note that a template function in C++ doesn't do what you described. It just creates a separae functions for each type. And of course you can do that in C also. In fact, that would raise less objections from your peers than casting.

KenJackson
Newbie Poster
13 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
 
© 2013 DaniWeb® LLC
Page rendered in 0.0600 seconds using 2.45MB