Search code examples
c++mfcc-strings

MFC CString Constructor action


CString Str1 = "ABC";
CString Str2 = Str1 + "123"; // Understandable
CString Str3 = "123" + Str1; // How does it work? Is there data overriding?

Does the last operation use CString '+' operator overloading, although Str1 is on the right of the '+'? Thanks of answering.


Solution

  • CString Str3 = "123" + Str1;
    

    Here you can see the various overloads of operator+ that CString supports and one of them includes the above example.

    Note: Concatenating two string literals like below is not supported for that would be equivalent to adding two pointers.

    CString Str3 = "123" + "456"