Newsgroups: comp.lang.c++ Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Can I hide data from my compiler? Message-ID: <1989Mar28.170031.20729@utzoo.uucp> Organization: U of Toronto Zoology References: <10133@bloom-beacon.MIT.EDU> Date: Tue, 28 Mar 89 17:00:31 GMT In article <10133@bloom-beacon.MIT.EDU> sorensen@hstbme.mit.edu.UUCP (Gregory Sorensen) writes: >Specifically, I'd like routines which I can pass a data object >made up of, say, floats or shorts, and use the same identical >code to process either, although I won't know _until run time_ >whether the data is made up of floats or shorts. Is there a way >to do this other than defining functions for each data object? Basically, no, although some languages (not C++) will do some of the work of defining the functions for you. The "same identical code" is not identical at the machine level: different machine instructions are used to manipulate the different data types, so there *have* to be separate functions, or the equivalent, down there somewhere. C++ lets you hide this from the outside world, and clever use of the C preprocessor might largely mechanize generating the functions, but basically C++ as it is currently defined isn't a lot of help when it comes to writing the code itself. You're going to have to consult some separate indication of what the data type is, and then invoke a suitable chunk of code. -- Welcome to Mars! Your | Henry Spencer at U of Toronto Zoology passport and visa, comrade? | uunet!attcan!utzoo!henry henry@zoo.toronto.edu