What does a period with a name in front of a function mean when to call it in Arduino code (C / C ++)?

advertisements

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?


"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.