title: Passing variable NAME to a function
body: <p><strong>Language:</strong> Visual C++, MFC</p>
  
  <p><strong>Environment:</strong> Visual Studio 2005</p>
  
  <p>So I posted a similar question, but I've come to realize that I was asking the wrong question. I'm trying to use a loop to call a function on several different variables, but somewhere along the way, the program is crashing. </p>
  
  <p>Simplified code is below, but I think it's actually easier to just explain it. I have a function that takes in a CString as a parameter. I have several variables I wish to feed to this function, so I put their names into an array, and I'm trying to pass them to the function that way.</p>
  
  <p><em><strong>// THE CODE BELOW IS WHAT I HAVE, BUT IT DOES NOT WORK //</em></strong></p>
  
  <p><em>Header File:</em></p>
  
  <pre><code>CString m_strTop;
  CString m_strLeft;
  CString m_strRight;
  CString m_strBottom;
  
  CString *var[4];
  </code></pre>
  
  <p><em>Source File:</em>
  <strong>Constructor()</strong></p>
  
  <pre><code>CString *var[4] = {
    &amp;m_strTop
  , &amp;m_strLeft
  , &amp;m_strRight
  , &amp;m_strBottom
  };
  </code></pre>
  
  <p><em>Source File:</em>
  <strong>theFunction()</strong></p>
  
  <pre><code>void myClass::DoDataExchange(CDataExchange* pDX)
  {
     CSAPrefsSubDlg::DoDataExchange(pDX);
  
     for(int i = 2001, j = 0; i &lt;= 2004; i++, j++)
     {
         // THE LINE BELOW IS WHERE THINGS GO WONKY, SPECIFICALLY AT &amp;var[j]
         DDX_Text(pDX, i, *var[j]); // 'i' is the ID of the textbox
     }
  } 
  </code></pre>
  
  <p><strong>-- What DDX_Text expects --</strong></p>
  
  <pre><code>void AFXAPI DDX_Text(
     CDataExchange* pDX,
     int nIDC,
     CString&amp; value 
  );
  </code></pre>
  
  <hr>
  
  <p>So like I said, I just need to feed the function the actual name of the variable. At least I think. What it's actually doing is establishing a connection between a text box in a dialog and the variable where the text box's input will be stored. I'm dereferencing correctly and everything, but I don't think this is the right approach.</p>
  
  <p>Thank you for any help. And to people who answered my previous question, my apologies for misrepresenting the issue.</p>