Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpcc05!hpsciz!hpdtczb!dent From: dent@hpdtczb.HP.COM (Steve Dent) Newsgroups: comp.lang.c++ Subject: Question about type conversion. Message-ID: <9580001@hpdtczb.HP.COM> Date: 30 Apr 91 00:20:36 GMT Organization: HP Design Tech Center - Santa Clara, CA Lines: 52 Sorry If this is question has been asked before. I'm developing a program which using existing C routines. One of the old C routines returns a variable which may have multiple types: i.e an integer, a double, or a pointer to a character. The user of this routine is provide conversion macros to convert the variable to a known type. The definition of the return structure is as follows: struct FIELD { int type; void *fieldValue; } A conversion macro would look like this: #define convInt(a) (*(int *) a->fieldValue) What I would like to do is create a C++ wrapper around this structure which will take care of conversion for the user. So instead of: var1 = convInt(ret1); It would look like this: var1 = ret1; I tried to create an overloaded operator= function as follows: inline void operator=(int tmp, FIELD *val) { tmp = (*(int *) val->fieldValue); } NOTE: this is simplified for an example. The problem is that the ATT 2.1 compiler gives me the following warning: CC: "s1.C", line 87: warning: non-member operator =() (anachronism) (1531) Which after looking up means that overloading the operator=() will only be supported as a member functions in future releases of the C++ language. I'm really trying to archive is type conversion not an assignment. The real question is how do I inform the C++ compiler of type conversion rule from a user defined class to a built in type? Is this possible? Steve Dent Design Technology Center Hewlett Packard