Borland C++ Builder 6 and string concatenation

馋奶兔 提交于 2019-12-06 12:39:10

The reason is that the type of "a" is char* (i.e.: pointer-to-char), which means when you write

"a" + "b"

you are trying to add to pointers together, which is not allowed.

When you create a String type, the operator+ is overloaded so

String a = "";
a + "b"

adds a pointer-to-char to a String, which has its own defintion of concatenation.

I'm not quite sure, but this is probably because of arguments. "a" in the first line is char*, so adding other strings still makes the result of char* and it is not possible to directly assign it o a String object. The second case shows, that if the first argument is of String type, all results are also Strings, so assignment is possible.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!