Sharing variables between methods

Hey! I wanna share variables between methods. Let's say I have a class such that:

void myClass::Begin(int theArray[]) { int myArray[3] = {theArray[0],theArray[1],theArray[2]}; }

Then I want the other methods to be able to use this variable, like:

void myClass::doSomething() { println(myArray[2]); }

But when I do this, I get an error saying that myArray[] was not declared in this scope.

Also, I tried to somehow initialize the variables in the constructor of the class, but it didn't work too.

Could somebody help me? I know it's a very newbie question, but I want to learn what's happening.

show the whole code. Where is myArray declared and how? If it is a global member of the class then you shouldn’t have any issues.

It should be int myArray[] in the constructor. It's where it is defined

Well, if it is defined in the constructor, then that's the only place it exists. Make it a global member of the class.

how can I turn this variable global?

class myClass {

     int aGlobalMember;

     myClass(int anArg){
          aGLobalMember = anArg;


Look at any tutorial on C++ classes. This is basic stuff.

I made it, I did, in my .h file:

class MyClass { public: int myArray[3];

and it didn't work.

Then I did it in my .cpp file, just before implementing the methods of the .h file, and it worked. Why?

It didn't work? What happened? What do you mean by didn't work? I can't see your screen or your project from here.

What code didn't work. Hopefully there was more than just those three lines. Post the whole thing.

@JustWannaLearn: Please read the two posts by Nick Gammon at the top of this Forum for guidelines on posting here, especially on the use of code tags when posting any source code. Nick also points out that seeing your source code is the fastest way for the rest of us to determine what the nature of your problem is. Posting all of your code, as suggested by Delta-G, is the first step in us helping you.