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. variable loop

variable loop

Scheduled Pinned Locked Moved C / C++ / MFC
database
3 Posts 3 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.
  • O Offline
    O Offline
    Oriented
    wrote on last edited by
    #1

    i have many many member variables named m_1 , m_2 , m_3 , m_4 ,.... and i want to access them using a for loop by an index (i) like that : for (int i=1; i

    A T 2 Replies Last reply
    0
    • O Oriented

      i have many many member variables named m_1 , m_2 , m_3 , m_4 ,.... and i want to access them using a for loop by an index (i) like that : for (int i=1; i

      A Offline
      A Offline
      Alvaro Mendez
      wrote on last edited by
      #2

      Two solutions: 1. Don't use member variables like that. Use an array: m_whatever[100], then it's easy to loop through it:

      for (int i = 0; m_whatever[i] = 0; ...)

      2. If you must do it with individual variables, you can use a macro, like this:

      #define M_(i) m_##i

      for (int i = 1; M_(i) = 0; ...)

      Regards, Alvaro


      Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.

      1 Reply Last reply
      0
      • O Oriented

        i have many many member variables named m_1 , m_2 , m_3 , m_4 ,.... and i want to access them using a for loop by an index (i) like that : for (int i=1; i

        T Offline
        T Offline
        Tom Larsen
        wrote on last edited by
        #3

        Assuming the series are all of the same type, you can make an array of pointers and walk that array. Take care to not fall off the end of the array.

        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