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 problem

CArray problem

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 5 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    CArray CMyClass::MyFunction(const char*,const char*) { CArray tmp; CString str_component = "test"; tmp.Add(str_component); return tmp; } =======Compile========= error C2558: class 'CArray' : no copy constructor available What's wrong ? What could I do (show me the example please)? Thanks a lot for your kindness

    M S 2 Replies Last reply
    0
    • L Lost User

      CArray CMyClass::MyFunction(const char*,const char*) { CArray tmp; CString str_component = "test"; tmp.Add(str_component); return tmp; } =======Compile========= error C2558: class 'CArray' : no copy constructor available What's wrong ? What could I do (show me the example please)? Thanks a lot for your kindness

      M Offline
      M Offline
      Martin Marvinski
      wrote on last edited by
      #2

      // make sure you have this include file: #include //Put this in your header CArray yourArray; //This is how you would do it in your cpp file yourArray.InsertAt(0,YourString); Try this, my first response wasn't formatted correctly. After a poor performance in London in 1899, Steinitz went insane and died a year later on August 12, 1900 at Wards Island, N.Y.

      R 1 Reply Last reply
      0
      • M Martin Marvinski

        // make sure you have this include file: #include //Put this in your header CArray yourArray; //This is how you would do it in your cpp file yourArray.InsertAt(0,YourString); Try this, my first response wasn't formatted correctly. After a poor performance in London in 1899, Steinitz went insane and died a year later on August 12, 1900 at Wards Island, N.Y.

        R Offline
        R Offline
        Renjith Ramachandran
        wrote on last edited by
        #3

        heyyyyyyyy just repaly after knowing the problem.he wants to retun a CArray from a function... :suss: me also face the same problem Renjith-The CPian.

        L 1 Reply Last reply
        0
        • R Renjith Ramachandran

          heyyyyyyyy just repaly after knowing the problem.he wants to retun a CArray from a function... :suss: me also face the same problem Renjith-The CPian.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          > he wants to retun a CArray from a function... > me also face the same problem Doesn't work! Solution: use std::vector and fire the responsible MS-Programmer :-D Really: To return a CArray by value requires the use of the copy constructor to copy the object (as the local instance will be destructed on return from the function. But-CArray has got no copy constructor, meaning CArray is almost useless. Greetings Jan-Henner Wurmbach

          C 1 Reply Last reply
          0
          • L Lost User

            > he wants to retun a CArray from a function... > me also face the same problem Doesn't work! Solution: use std::vector and fire the responsible MS-Programmer :-D Really: To return a CArray by value requires the use of the copy constructor to copy the object (as the local instance will be destructed on return from the function. But-CArray has got no copy constructor, meaning CArray is almost useless. Greetings Jan-Henner Wurmbach

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

            jhwurmbach wrote: CArray is almost useless. YES YES YES YES YES !!!!! Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002 Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002

            1 Reply Last reply
            0
            • L Lost User

              CArray CMyClass::MyFunction(const char*,const char*) { CArray tmp; CString str_component = "test"; tmp.Add(str_component); return tmp; } =======Compile========= error C2558: class 'CArray' : no copy constructor available What's wrong ? What could I do (show me the example please)? Thanks a lot for your kindness

              S Offline
              S Offline
              Sprudling
              wrote on last edited by
              #6

              Instead of returning a CArray (which is impossible no matter what you do since it's a template class; but that's another story) do this:

              void CMyClass::MyFunction(CStringArray& a)
              {
              CString str_component = "test";
              a.add(str_component);
              }

              #include "afxtempl.h" to use the class 'CStringArray'. To use 'MyFunction' do like this:

              void CMyClass::AnotherFunction()
              {
              CStringArray myArray;
              this->MyFunction(myArray);
              }

              After the call to 'MyFunction' the string is still added since the array is sent by reference. And there is no need for a copy constructor for the same reason. Sprudling

              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