How do I define an implicit typecast from my class to a scalar?

Posted by Delan Azabani on Stack Overflow See other posts from Stack Overflow or by Delan Azabani
Published on 2010-05-02T09:33:48Z Indexed on 2010/05/02 9:37 UTC
Read the original article Hit count: 234

Filed under:
|
|
|
|

I have the following code, which uses a Unicode string class from a library that I'm writing:

#include <cstdio>
#include "ucpp"
main() {
  ustring a = "test";
  ustring b = "ing";
  ustring c = "- -";
  ustring d;
  d = "cafe\xcc\x81";
  printf("%s\n", (a + b + c[1] + d).encode());
}

The encode method of the ustring class instances converts the internal Unicode into a UTF-8 char *. However, because I don't have access to the char class definition, I am unsure on how I can define an implicit typecast (so that I don't have to manually call encode when using with printf, etc).

© Stack Overflow or respective owner

Related posts about c++

Related posts about implicit