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. how to use an Array of a class?

how to use an Array of a class?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorialquestion
4 Posts 4 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.
  • M Offline
    M Offline
    MohammadAmiry
    wrote on last edited by
    #1

    Hi I have a class named CClipSaver and I want to create an array of this class. I do this as follows:

    CClipSaver* Clips[10];
    .
    .
    .
    Clips[i]=new CClipSaver;
    Clips[i]->Save();
    .
    .
    .
    

    But it crashes! Note: When I do not use array (i.e. CClipSaver * Clip; Clip=new ClipSaver(); Clip.Save(); ) everything works fine. How should I declare and use the array?

    P P 2 Replies Last reply
    0
    • M MohammadAmiry

      Hi I have a class named CClipSaver and I want to create an array of this class. I do this as follows:

      CClipSaver* Clips[10];
      .
      .
      .
      Clips[i]=new CClipSaver;
      Clips[i]->Save();
      .
      .
      .
      

      But it crashes! Note: When I do not use array (i.e. CClipSaver * Clip; Clip=new ClipSaver(); Clip.Save(); ) everything works fine. How should I declare and use the array?

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      What is the value of i when it "crashes"? (whatever "crashes" means)


      You may be right
      I may be crazy
      -- Billy Joel --

      Within you lies the power for good, use it!!!

      A 1 Reply Last reply
      0
      • P PJ Arends

        What is the value of i when it "crashes"? (whatever "crashes" means)


        You may be right
        I may be crazy
        -- Billy Joel --

        Within you lies the power for good, use it!!!

        A Offline
        A Offline
        arr cpp
        wrote on last edited by
        #3

        Remember that when using arrays array[10] the tenth value is array[9] the value array[10] is out of the definition and may cause writting out of memory...

        1 Reply Last reply
        0
        • M MohammadAmiry

          Hi I have a class named CClipSaver and I want to create an array of this class. I do this as follows:

          CClipSaver* Clips[10];
          .
          .
          .
          Clips[i]=new CClipSaver;
          Clips[i]->Save();
          .
          .
          .
          

          But it crashes! Note: When I do not use array (i.e. CClipSaver * Clip; Clip=new ClipSaver(); Clip.Save(); ) everything works fine. How should I declare and use the array?

          P Offline
          P Offline
          Parthi_Appu
          wrote on last edited by
          #4

          MohammadAmiry wrote:

          Clip=new ClipSaver(); Clip.Save(); everything works fine

          Hope its a typo Error


          Do your Duty and Don't expect the Result
          Rate this Post, if I helped You

          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