Static method

Hi guys.
I have a question.
Can I declare a static method in newheader.cpp or I should declare in newheader.h , or has no difference.
Thanks.

WTF is a static method?

Mark

Static method

Ach, sucked me in with that link. Oh well try this: Static method

leoncorleone:
Can I declare a static method in newheader.cpp or I should declare in newheader.h , or has no difference.

Do you mean declare or define?

Okay , But I don't know what is wrong with Arduino IDE, I compile my code in another compiler , and It went well.
My code is the same as below , I want to use c variable in another function in my class.

//myheader.h
String c;
static void aaa(String b)
{
c=b;
}
//main.ino
void setup()
{
I2CH::aaa("Hello");
}

error:
I2CH.h:11:10: error: invalid use of member 'I2CH::c' in static member function String c;

Sorry I think I'm in worng. :frowning:
Thank you all.... for being patient with a newbie.

Could somebody tell me how to define that , please .I've searched so much , but nothing.

Could somebody tell me how to define that

How to define what?

Your myheader.h does not appear to define a class. So,

I2CH::aaa("Hello");

is nonsense.

No, that is inside a class named I2CH , that is just part of code.

that is just part of code.

OK. That's fair.

Here is part of the answer. You need to ...

Which?

Which?

Which what? The correct one, of course!

Which

That is so interesting. :o
When I define it to main.ino and use the static function with a non-static variable , Ide doesn't have any error and everything goes well.
But when I define it in my class and include the header to main.ino , Ide gets that error, even if I don't use the static function.
Looking forward to hear from you. 8)
Thanks.

Looking forward to hear from you.

Looking forward to seeing ALL of your code, first.

You just want answer , but what? I don't know.

I don't know.

Obviously.

I can't see anything particularly challenging about understanding "Post ALL of your code". YMMV.

by god, put it out of its misery

static method only works with static member variables (across all instances).

leoncorleone:
You just want answer , but what? I don't know.

Get your code that doesn't compile. Zip it up into a file. Attach that file to a post. Trying to describe your code is like trying to describe a colour. Much easier to actually post it.