Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!uakari.primate.wisc.edu!caesar.cs.montana.edu!ogicse!emory!mephisto!prism!chmsr!patty From: patty@chmsr (Patty Jones) Newsgroups: comp.lang.c++ Subject: contravariance confusion Message-ID: <5063@hydra.gatech.EDU> Date: 19 Jan 90 14:04:00 GMT Sender: news@prism.gatech.EDU Reply-To: patty@chmsr.gatech.edu (Patty Jones) Organization: Center for Human-Machine Systems Research - Ga Tech Lines: 93 What does the following 1.36.1 g++ compiler warning mean?? warning: contravariance violation for method types ignored and could this become a serious problem later on as our program grows? Also, I'm not sure I understand what contravariance means -- is that when you pass a pointer to member of class "base" to a function that expects a pointer to a member of class "derived"? But in our situation we have defined a function (SchedEvent; see below) to expect pointers to class "base" and we actually use the SchedEvent function with pointers to class "derived". A bit of background: We are working on an interactive real-time simulation in C++ (in the domain of satellite ground control) using the g++ 1.36.1 compiler on Suns. We have a function that creates event objects which are maintained on an event list; the function prototype is as follows: SchedEvent(int, ActiveSimulationObject *, void_fp, char *) where 1) the first argument is an integer which represents the time the event is scheduled to occur, 2) a pointer to an ActiveSimulationObject object (ActiveSimulationObject is our base class); this points to the object to whom something is going to occur, 3) void_fp is a pointer to a member function in class ActiveSimulationObject (i.e., typedef void (ActiveSimulationObject :: *void_fp) (...); ) 4) the fourth argument is a character string that represents the arguments to the function pointed to by void_fp. Our program works but we are getting the "contravariance" compiler warning on lines where we call SchedEvent. We are calling SchedEvent with pointers to derived classes and their members. For example, part of the class hierarchy we have right now is as follows: ActiveSimulationObject | | SpacecraftComponent | | TapeRecorder and part of the class definition for TapeRecorder is as follows: class TapeRecorder : public SpacecraftComponent { char *mode; // can be "record", "standby", "playback", "fast forward" . . public: void setMode(char *m) { mode = m; } . . }; And finally, we declare: TapeRecorder TR1; To schedule TR1 to go into "record" mode at time 5, we do the following: SchedEvent(5, &TR1, &TR1.setMode, "record"); and as I said, we get the "contravariance" warning on lines such as this where we call SchedEvent. thanks for your help! patty Patty Jones Center for Human-Machine Systems Research School of Industrial and Systems Engineering Georgia Institute of Technology, Atlanta, GA 30332 UUCP: patty@chmsr.UUCP {backbones}!gatech!chmsr!patty INTERNET: patty@chmsr.gatech.edu Patty Jones Center for Human-Machine Systems Research School of Industrial and Systems Engineering Georgia Institute of Technology, Atlanta, GA 30332 UUCP: patty@chmsr.UUCP {backbones}!gatech!chmsr!patty INTERNET: patty@chmsr.gatech.edu