Path: utzoo!attcan!uunet!samsung!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!uw-beaver!ssc-vax!fluke!dyndata!dan From: dan@dyndata.UUCP (Dan Everhart) Newsgroups: comp.lang.c++ Subject: implicit conv to int in subscript Message-ID: <684@dyndata.UUCP> Date: 25 May 90 05:38:17 GMT Organization: Dynamic Data & Electronics, Edmonds WA Lines: 49 Consider the following program: class Index { public: Index (int i) : v (i) {}; operator int () { return v; }; private: int v; }; Index x (0); char ac [10]; f () { ac [x] = 'a'; // this line fails ac [(int) x] = 'a'; ac [int (x)] = 'a'; } On the marked line, I expected the compiler to make an implicit conversion of x to int, since the Index class has an operator int () function defined. Zortech 2.06 gives the error message: "opint.cpp", line 17 Syntax error: illegal pointer arithmetic Had: and: The subsequent two lines, with their explicit conversions, compile fine. Although I could not find any example in The C++ Primer of exactly this nature, there is a close one on p. 283 where Lippman defines a SmallInt class, with similar conversion operators and says, "A SmallInt class object can now be used *anywhere* in int object can be used." (Emphasis mine.) Taking a clue from the error message, I also tried adding the line friend char & operator + (char *, Index); to the class definition, attempting to provide assistance with the pointer arithmetic. It made no difference. So, should this work?