3

What does a period with a name before a function mean when calling it in Arduino code (C/C++)?

For example, I am using an OLED display library and one function is called like this:

display.setTextSize(1);

I know what this function does, but what does the syntax mean where there is some variable "display" or something before it?

In other words, why is a function called this way versus a normal call with just the function name and input?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
ltkenbo
  • 71
  • 2
  • 5

2 Answers2

5

"display" is an instance of an object, or a reference to some global/system variable. The "setTextSize" method is a member of that object. The end result means that you are setting the text size of, or on, "display".

This lets you do things more concisely by being able to say display.setTextSize(1), foo.setTextSize(1) and bar.setTextSize(1) without having to specify unique functions for each different item on which you are setting the text size.

Within setTextSize you will probably see "this". "this" in only this one instance means "display". If you used bar.setTextSize(1), "this" would mean "bar" and so on.

oooyaya
  • 1,773
  • 1
  • 15
  • 39
0

I could be incredibly wrong, but I think its got to do with structures. In the arduino environment there's a few different functions that revolve around using serial communication. They have it set up as a library that gets called on whenever you use Serial.something(); The something could be any of the functions that is part of serial, like Serial.read();

EDIT forgot to put a source in. http://arduino.cc/en/Reference/Serial

Apologies if I'm way off, still new at this, and also can't figure out how to just make a comment.

Solidus
  • 23
  • 4