title: How to access the variable from another function in a class
body: <p>So I have experience using programming languages and just switched over to C++. Now I have created a few working applications but I always stumble upon the same problem. I don't exactly know what everything is called in the code. You have a class which obvious to see since the has written class before it. And you also have some sort of functions attached to the class are these called instances? And is the class the object it referring to by for example class::function.</p>
  
  <p>But my main question was how can I access the variables from another function within the same class file. I have included an example below explaining what I want to achieve. I already tried a lot of things and googled a lot. I tried code pasting code creating setting and getting functions, calling the class to get and set the variable but I can't get it to work. I've spend a lot of time fixing this very basic problem. Could someone explain me what is called what in this code (Class,Object,Instance). And explain me the most efficient way to receive data from another function in the same .cpp file.</p>
  
  <p>Thanks</p>
  
  <p>load_data.h</p>
  
  <pre><code>#pragma once
  
  class load_data
  {
  
  public:
  
      static int data[13];
  
      load_data();
      static void test2();
  
  };
  </code></pre>
  
  <p>load_data.cpp</p>
  
  <pre><code>#include "load_data.h"
  #include "abc.h"
  
  
  load_data::load_data()
  {
      int data[3]; // Initializing the array
  
      data[0] = abc::LoadImage("textures/1.png");
      data[1] = abc::LoadImage("textures/2.png");
      data[2] = abc::LoadImage("textures/3.png");
  }
  
  void load_data::test2()
  {
  
      abc::CreateSprite(1, data[0]); 
      abc::SetSpritePosition(1, 0, 0);
      abc::SetSpriteScale(1, 3, 3);
  
  // Now I get an error saying it has no data. Which however is set in
  // load_data(). But since each function gets its own variables this one will be empty.
  
      abc::CreateSprite(2, data[1]);
      abc::SetSpritePosition(2, 64, 64);
      abc::SetSpriteScale(2, 3, 3);
  
      abc::CreateSprite(3, data[2]);
      abc::SetSpritePosition(3, 128, 128);
      abc::SetSpriteScale(3, 3, 3);
  
  }
  </code></pre>