Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CArray template class

CArray template class

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studioquestion
13 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Chris Losinger

    does CMyStruct have an "operator =" member ? looks like that's what the compiler wants. have you considered std::vector instead of CArray? overall, std::vector is a nicer way to deal with an array of things. -c


    Alcohol is the anesthesia by which we endure the operation of life. -- George Bernard Shaw

    Smaller Animals Software

    R Offline
    R Offline
    Richard Lewis
    wrote on last edited by
    #4

    hi there, just wanted to let you'll know: When i remove the CStringArray from the structure it works!

    H 1 Reply Last reply
    0
    • R Richard Lewis

      hi there, just wanted to let you'll know: When i remove the CStringArray from the structure it works!

      H Offline
      H Offline
      Holger Persch
      wrote on last edited by
      #5

      This is because of CStringArray has no "=" operator. Best regards Holger Persch

      R 1 Reply Last reply
      0
      • H Holger Persch

        This is because of CStringArray has no "=" operator. Best regards Holger Persch

        R Offline
        R Offline
        Richard Lewis
        wrote on last edited by
        #6

        OK thats fine, but what happens when I **NEED** a CStringArray in my structure. (Right now i have replaced the CStringArray by a char**) but thats not very elegant!)

        C H 2 Replies Last reply
        0
        • R Richard Lewis

          OK thats fine, but what happens when I **NEED** a CStringArray in my structure. (Right now i have replaced the CStringArray by a char**) but thats not very elegant!)

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #7

          then you need to write an "=" operator for your struct. in it, you'll copy all the data items from the input struct to "this". -c


          Alcohol is the anesthesia by which we endure the operation of life. -- George Bernard Shaw

          Smaller Animals Software

          R 1 Reply Last reply
          0
          • C Chris Losinger

            then you need to write an "=" operator for your struct. in it, you'll copy all the data items from the input struct to "this". -c


            Alcohol is the anesthesia by which we endure the operation of life. -- George Bernard Shaw

            Smaller Animals Software

            R Offline
            R Offline
            Richard Lewis
            wrote on last edited by
            #8

            Do you mean implementing a = operator that copies from one CStringArray into another. P.S:I say this, because i am now using a statically allocated char[][], thereby eliminating the need for copying!

            C 1 Reply Last reply
            0
            • R Richard Lewis

              OK thats fine, but what happens when I **NEED** a CStringArray in my structure. (Right now i have replaced the CStringArray by a char**) but thats not very elegant!)

              H Offline
              H Offline
              Holger Persch
              wrote on last edited by
              #9

              The "=" operator can look like this:

              class CMyClass
              {
              .
              .
              .

              const CMyClass &operator =(const CMyClass &src)
              {
              	m\_String = src.m\_String;
              
              	m\_StringArray.RemoveAll();
              	m\_StringArray.Append(src.m\_StringArray);
              	m\_StringArray.FreeExtra();
              
              	return \*this;
              }
              

              public:
              CString m_String;
              CStringArray m_StringArray;
              };

              Best regards Holger Persch

              R T 2 Replies Last reply
              0
              • H Holger Persch

                The "=" operator can look like this:

                class CMyClass
                {
                .
                .
                .

                const CMyClass &operator =(const CMyClass &src)
                {
                	m\_String = src.m\_String;
                
                	m\_StringArray.RemoveAll();
                	m\_StringArray.Append(src.m\_StringArray);
                	m\_StringArray.FreeExtra();
                
                	return \*this;
                }
                

                public:
                CString m_String;
                CStringArray m_StringArray;
                };

                Best regards Holger Persch

                R Offline
                R Offline
                Richard Lewis
                wrote on last edited by
                #10

                Thanks so much for this Holger, that was very kind of you.

                1 Reply Last reply
                0
                • R Richard Lewis

                  Do you mean implementing a = operator that copies from one CStringArray into another. P.S:I say this, because i am now using a statically allocated char[][], thereby eliminating the need for copying!

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #11

                  Yes - you need to impliment operator = for CStringArray, as Chris has already said twice now. As he has also said, the MFC container classes are plain ugly compared to STL, and std::vector would solve all of these problems as well as opening up a whole world of elegant container design to you. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

                  1 Reply Last reply
                  0
                  • H Holger Persch

                    The "=" operator can look like this:

                    class CMyClass
                    {
                    .
                    .
                    .

                    const CMyClass &operator =(const CMyClass &src)
                    {
                    	m\_String = src.m\_String;
                    
                    	m\_StringArray.RemoveAll();
                    	m\_StringArray.Append(src.m\_StringArray);
                    	m\_StringArray.FreeExtra();
                    
                    	return \*this;
                    }
                    

                    public:
                    CString m_String;
                    CStringArray m_StringArray;
                    };

                    Best regards Holger Persch

                    T Offline
                    T Offline
                    Tomasz Sowinski
                    wrote on last edited by
                    #12

                    Is there any reason for which you prefer RemoveAll/Append/FreeExtra over CStringArray::Copy? Tomasz Sowinski -- http://www.shooltz.com

                    *** Si fractum non sit, noli id reficere. ***

                    H 1 Reply Last reply
                    0
                    • T Tomasz Sowinski

                      Is there any reason for which you prefer RemoveAll/Append/FreeExtra over CStringArray::Copy? Tomasz Sowinski -- http://www.shooltz.com

                      *** Si fractum non sit, noli id reficere. ***

                      H Offline
                      H Offline
                      Holger Persch
                      wrote on last edited by
                      #13

                      No, i have just not recognized that there exists a copy method :-O. Best regards Holger Persch

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups