Access to static variable in class.

Hello to all.
I have a question.I Have a header that I want to access from my project to a static variable of it.
But compiler got an error.Below is MyHeader.h and test.ino.
Thanks again.

MyHeader.h (165 Bytes)

test.ino (146 Bytes)

What the...
What error?
What MyHeader.h?
What test.ino?
What static variable?

Sorry I forgot it.

Post your code, don't attach it.
Post the exact error the compiler reported.

Here is my code:

//MyHeader.h
#ifndef MyHeader_H
#define MyHeader_H



class MyHeader
{
	public:
		
	static int var1=0;
	static void fun1()
	{
		int a=5;
		var1=a;
	}
	
};
#endif
//test.ino
#include <MyHeader.h>

void setup() {
  // put your setup code here, to run once:
MyHeader::fun1();
int c=MyHeader::var1;
}

void loop() {
  

}

error:
C:\Users\Leon\Documents\Arduino\libraries\MyHeader/MyHeader.h:10:18: error: ISO C++ forbids in-class initialization of non-const static member 'MyHeader::var1'
static int var1=0;

. . . And don't start a new thread when the subject is the same.

sorry.but that wasn't my fault.
It was internet.

See Reply #1, second line.

error:
C:\Users\Leon\Documents\Arduino\libraries\MyHeader/MyHeader.h:10:18: error: ISO C++ forbids in-class initialization of non-const static member 'MyHeader::var1'
static int var1=0;

C++ forbids in-class initialization of non-const static member 'MyHeader::var1

They don't come much clearer than that.

What should I do.?? :frowning: :frowning:

leoncorleone:
What should I do.?? :frowning: :frowning:

What are you trying to do?

How can I access to 'a' variable in a class that it is inside a static function, in my ino file?

leoncorleone:
How can I access to 'a' variable in a class that it is in a static function in my ino file?

Why do you need to do that?

Because I have a function the same as top and I want to access to a variable inside the function as a flag.???

How can I access to 'a' variable in a class that it is inside a static function, in my ino file?

The question does not even make sense. A function, static or otherwise, can not have a class in it. It could have an instance of a class.

Sorry I am a newbie.
If you can please edit my code.
Thanks.

Nobody can answer clearly my simple question.????

It isn't clear ( to me) what you are trying to do, but thisC++ forbids in-class initialization of non-const static member 'MyHeader::var1 must be a useful clue.

You should separate your header file into a header file and a source file. Move everything that actually sets values into the source file. Then, the messages will become much clearer, as they will refer to the file that you are making the mistake in.