Topic: Global conversion operator?


Author: pirkin@hotmail.com ("Ilya Pirkin")
Date: Sat, 1 Oct 2005 17:00:43 GMT
Raw View
Hi everyone

Does C++ have global conversion operators at all? Brief search though the
standard did not reveal such functionality so I'm curious why I can write
global operator== but not global conversion operator from one class to
another? Thanks


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: v.Abazarov@comAcast.net ("Victor Bazarov")
Date: Sat, 1 Oct 2005 22:46:56 GMT
Raw View
"Ilya Pirkin" wrote:
> Does C++ have global conversion operators at all?

Yes, for built-in types.

> Brief search though
> the standard did not reveal such functionality so I'm curious why I
> can write global operator== but not global conversion operator from
> one class to another? Thanks

Conversion from one class to another is either done by a converting
constructor defined in the 'another' class or by a conversion operator
defined in the 'one' class.  If neither of two classes are written by
you, and you need to introduce such conversion, write a function

   <anotherclass> to_another(const <oneclass>&);

and use it.

V


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]