title: can global variables be accessed and modified in various classes in C++
body: <p>I have run into code spaghetti where i need to instrument flow control i.e., send data one at a time. How can i use global variable to solve this? If global variables don't work, what is the way to access and modify variables in multiples functions which could be in different classes</p>
  
  <p>I tried the following (I am pasting partial code) but it gave me ld error that I could not resolve. I want to ask what might be the best and clean approach to solve this.</p>
  
  <p><strong>file1.h</strong></p>
  
  <pre><code>int data_received; //global variable
  class abc
  {
  .
  .
  .
  public:
    void send_data(..)
  .
  .
  .
  };
  </code></pre>
  
  <p><strong>file1.c</strong></p>
  
  <pre><code>void send_data()
  {
    while(!end_of_file)
    {
      read_line;
      data_received = 0;
      transmit_data(line);
      while(data_received == 0)
        cout&lt;&lt;"waiting for response before proceeding\n";
  
    }
  
  }
  </code></pre>
  
  <p><strong>file2.c</strong></p>
  
  <pre><code>//data receive class
  
  void transmit_data()
  {
   ....
   ....
   ....
  //data sent upstream
   data_received = 1;
  }
  </code></pre>
  
  <p>I have searched many posts on stackoverflow but there is no clear answer. Some suggest to use extern variable but no clear example of external variable being modified in more than one class functions.</p>