Re: Aaahhrg! Trouble passing an array of structs to a function!
"Robby" <Robby@discussions.microsoft.com> wrote in message
news:9470DD22-F836-40C9-A4CF-800CCEE38E11@microsoft.com...
For example, if I have say 20 different types of arrays of structures and
a
particular member of every strcture needs to be tested, updated or
manipulated always using a specific logic, what should one do. Create 20
different functions... one for each array of structures ?
In the C language that is your only choice. A function can only work with
the types it was designed for. The fact that a particular member of every
structure type happens to have the same name is of no help to the compiler:
They are different.
In my humble
opinion that would appear to be redundant. Because what would happen if 20
turns to 40, 100 or even 500? So I don't know any other approach to this
scenario but to try to do what I am doing here.
C++ has two smart ways to deal with such situations. If all the types
inherit from a common parent then the function can be written to understand
the parent, and all of the children types can be passed to it. Or a C++
template can be written: This is just an automated way to get the compiler
to write the 20, 40 or even 500 functions.
--
Scott McPhillips [VC++ MVP]