MFC CString Constructor action












2















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.










share|improve this question



























    2















    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.










    share|improve this question

























      2












      2








      2








      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.










      share|improve this question














      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.







      c++ mfc c-strings






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 6:41









      SagiSagi

      133




      133
























          2 Answers
          2






          active

          oldest

          votes


















          1














          The MFC/ATL CStringT class template provides the following operator+ operators as free functions:




          friend CStringT operator+(const CStringT& str1, const CStringT& str2);
          friend CStringT operator+(const CStringT& str1, PCXSTR psz2);
          friend CStringT operator+(PCXSTR psz1, const CStringT& str2,);
          friend CStringT operator+(char ch1, const CStringT& str2,);
          friend CStringT operator+(const CStringT& str1, char ch2);
          friend CStringT operator+(const CStringT& str1, wchar_t ch2);
          friend CStringT operator+(wchar_t ch1, const CStringT& str2);



          The statement CString Str3 = "123" + Str1; cannot use a class member, as there is no class object on the left-hand side of the + expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.



          Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW) and prepending string literals with an L (L"123").






          share|improve this answer

































            1














            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"





            share|improve this answer





















            • 2





              CString isn't Microsoft's version of std::string. It is part of Microsoft's MFC. MFC's CString is completely unrelated to std::string.

              – IInspectable
              Nov 15 '18 at 8:42











            • I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.

              – P.W
              Nov 15 '18 at 8:44











            • That still links to outdated documentation, that's no longer correct.

              – IInspectable
              Nov 15 '18 at 8:52











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313783%2fmfc-cstring-constructor-action%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The MFC/ATL CStringT class template provides the following operator+ operators as free functions:




            friend CStringT operator+(const CStringT& str1, const CStringT& str2);
            friend CStringT operator+(const CStringT& str1, PCXSTR psz2);
            friend CStringT operator+(PCXSTR psz1, const CStringT& str2,);
            friend CStringT operator+(char ch1, const CStringT& str2,);
            friend CStringT operator+(const CStringT& str1, char ch2);
            friend CStringT operator+(const CStringT& str1, wchar_t ch2);
            friend CStringT operator+(wchar_t ch1, const CStringT& str2);



            The statement CString Str3 = "123" + Str1; cannot use a class member, as there is no class object on the left-hand side of the + expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.



            Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW) and prepending string literals with an L (L"123").






            share|improve this answer






























              1














              The MFC/ATL CStringT class template provides the following operator+ operators as free functions:




              friend CStringT operator+(const CStringT& str1, const CStringT& str2);
              friend CStringT operator+(const CStringT& str1, PCXSTR psz2);
              friend CStringT operator+(PCXSTR psz1, const CStringT& str2,);
              friend CStringT operator+(char ch1, const CStringT& str2,);
              friend CStringT operator+(const CStringT& str1, char ch2);
              friend CStringT operator+(const CStringT& str1, wchar_t ch2);
              friend CStringT operator+(wchar_t ch1, const CStringT& str2);



              The statement CString Str3 = "123" + Str1; cannot use a class member, as there is no class object on the left-hand side of the + expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.



              Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW) and prepending string literals with an L (L"123").






              share|improve this answer




























                1












                1








                1







                The MFC/ATL CStringT class template provides the following operator+ operators as free functions:




                friend CStringT operator+(const CStringT& str1, const CStringT& str2);
                friend CStringT operator+(const CStringT& str1, PCXSTR psz2);
                friend CStringT operator+(PCXSTR psz1, const CStringT& str2,);
                friend CStringT operator+(char ch1, const CStringT& str2,);
                friend CStringT operator+(const CStringT& str1, char ch2);
                friend CStringT operator+(const CStringT& str1, wchar_t ch2);
                friend CStringT operator+(wchar_t ch1, const CStringT& str2);



                The statement CString Str3 = "123" + Str1; cannot use a class member, as there is no class object on the left-hand side of the + expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.



                Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW) and prepending string literals with an L (L"123").






                share|improve this answer















                The MFC/ATL CStringT class template provides the following operator+ operators as free functions:




                friend CStringT operator+(const CStringT& str1, const CStringT& str2);
                friend CStringT operator+(const CStringT& str1, PCXSTR psz2);
                friend CStringT operator+(PCXSTR psz1, const CStringT& str2,);
                friend CStringT operator+(char ch1, const CStringT& str2,);
                friend CStringT operator+(const CStringT& str1, char ch2);
                friend CStringT operator+(const CStringT& str1, wchar_t ch2);
                friend CStringT operator+(wchar_t ch1, const CStringT& str2);



                The statement CString Str3 = "123" + Str1; cannot use a class member, as there is no class object on the left-hand side of the + expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.



                Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW) and prepending string literals with an L (L"123").







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 15 '18 at 9:11

























                answered Nov 15 '18 at 8:50









                IInspectableIInspectable

                26.2k54396




                26.2k54396

























                    1














                    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"





                    share|improve this answer





















                    • 2





                      CString isn't Microsoft's version of std::string. It is part of Microsoft's MFC. MFC's CString is completely unrelated to std::string.

                      – IInspectable
                      Nov 15 '18 at 8:42











                    • I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.

                      – P.W
                      Nov 15 '18 at 8:44











                    • That still links to outdated documentation, that's no longer correct.

                      – IInspectable
                      Nov 15 '18 at 8:52
















                    1














                    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"





                    share|improve this answer





















                    • 2





                      CString isn't Microsoft's version of std::string. It is part of Microsoft's MFC. MFC's CString is completely unrelated to std::string.

                      – IInspectable
                      Nov 15 '18 at 8:42











                    • I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.

                      – P.W
                      Nov 15 '18 at 8:44











                    • That still links to outdated documentation, that's no longer correct.

                      – IInspectable
                      Nov 15 '18 at 8:52














                    1












                    1








                    1







                    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"





                    share|improve this answer















                    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"






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 15 '18 at 8:48

























                    answered Nov 15 '18 at 6:55









                    P.WP.W

                    15.5k31453




                    15.5k31453








                    • 2





                      CString isn't Microsoft's version of std::string. It is part of Microsoft's MFC. MFC's CString is completely unrelated to std::string.

                      – IInspectable
                      Nov 15 '18 at 8:42











                    • I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.

                      – P.W
                      Nov 15 '18 at 8:44











                    • That still links to outdated documentation, that's no longer correct.

                      – IInspectable
                      Nov 15 '18 at 8:52














                    • 2





                      CString isn't Microsoft's version of std::string. It is part of Microsoft's MFC. MFC's CString is completely unrelated to std::string.

                      – IInspectable
                      Nov 15 '18 at 8:42











                    • I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.

                      – P.W
                      Nov 15 '18 at 8:44











                    • That still links to outdated documentation, that's no longer correct.

                      – IInspectable
                      Nov 15 '18 at 8:52








                    2




                    2





                    CString isn't Microsoft's version of std::string. It is part of Microsoft's MFC. MFC's CString is completely unrelated to std::string.

                    – IInspectable
                    Nov 15 '18 at 8:42





                    CString isn't Microsoft's version of std::string. It is part of Microsoft's MFC. MFC's CString is completely unrelated to std::string.

                    – IInspectable
                    Nov 15 '18 at 8:42













                    I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.

                    – P.W
                    Nov 15 '18 at 8:44





                    I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.

                    – P.W
                    Nov 15 '18 at 8:44













                    That still links to outdated documentation, that's no longer correct.

                    – IInspectable
                    Nov 15 '18 at 8:52





                    That still links to outdated documentation, that's no longer correct.

                    – IInspectable
                    Nov 15 '18 at 8:52


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313783%2fmfc-cstring-constructor-action%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues