richer@well.UUCP (Mark H. Richer) (09/28/88)
We have been writing code using our own object-oriented extension to C --- sort of a cross between Objective C and Flavors. We plan to port to C++ real soon now, but we do not even have a C++ compiler here yet to figure out exactly what can and can't be done in C++. We have some questions about how we can port certain features of our current environment to C++: 1. Is it possible to have "computed" selectors in C++? In other words, can the virtual member function to be applied to a set of arguments be determined at runtime? I believe this is the same as asking can you use the address of a virtual function to call the function at runtime (in other words, using a function pointer parameter). I haven't found anything in the manual (Stroustrup, 1986) that definitely says you can or can't. (If I had a C++ compiler I could obviously just try it and see what happens.) On page 125 it says "There are only two things one can do to a function: call it and take its address. The pointer obtained by taking the address of a function can then be used to call the function." Okay so far so good, but this just restates what we know about standard C. Can we assume that the same is true for all functions --- in line functions, member functions, virtual member functions, and overloaded function names? Page 129: "It is possible to take the address of an inline function, and also to take the address of an overloaded function." On page 276 it says "It is legal to apply the address-of operator to a member function. However, the type of the resulting pointer to function is undefined, so that any use of it is implementation dependent." Since virtual functions are member functions, I assume this applies to them equally. But we can't understand the second sentence and what it implies. On page 291 it says "The address-of operator & may only be applied to an overloaded name in an assignment or an initialization where the type expected determines which function to take the address of." Aren't virtual functions similar to overloaded names? Is this restriction relevant to virtual functions as well overloaded function names? Could someone explain? 2. We know that C++ does not support metaclasses or class objects. "Class object" is a confusing term, but we can't think of one that is any less confusing. (Unfortunately the C++ manual uses the same phrase for something else.) A "class object" is an instance that "represents" the whole class --- it is not an instance of class, but I think it is generally (in other object-oriented systems) an instance of the class' metaclass. As a result you can then have class variables and class methods (or member functions in C++). A "New" function can be defined on a class object so that you can send a NEW message to a class to create a new instance of itself. You can do lots of other things as well. Has anyone implemented this type of facility in C++? Mark Richer Mountain Lake Software, Inc.