Hi,
I have some knowledge about c++ objects and inheritance of classes.
But the following line confused me.
It's from an example for the ePaper Library from ZinggJM (GxEPD2)
The line is used to create the display object:
GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
As far as I understand this line is working with templates?
But what's exactly happening here? --> especially at the beginning.
Thanks for your help
GxEPD2_BW
...is the template name.
<>
...is how we know it is a template.
GxEPD2_270
...is the first argument for the template.
GxEPD2_270::HEIGHT
...is the second argument for the template.
Presumably, all that stuff above expands to a class definition.
display
...is the name of an instance of that class.
GxEPD2_270(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)
...is the one argument passed to the constructor.
Ok. Thanks a lot.
This helps.
But what does GxEPD2_270::HEIGHT mean?
GxEPD2_270 is the class (GxEPD2_BW is base class) and HEIGHT is a variable definied in this class header (number of pixels for this display)
Post a link to the library.
McMorton:
But what does GxEPD2_270::HEIGHT mean?
GxEPD2_270
...is a namespace. That can include a class, enum, or namespace.
::
...is the scope resolution operator.
HEIGHT
...is something in the GxEPD2_270 namesapce. It could be a constant or a type.
GxEPD2_270 is the class
Which also makes it a namespace.
HEIGHT is a variable definied in this class header (number of pixels for this display)
So...
GxEPD2_270::HEIGHT
Pass HEIGHT (a variable) from the GxEPD2_270 namespace (a class) as the second argument to the template. As a template argument HEIGHT has to be a compile-time constant.
Thanks. I think now I understand.
gfvalvo:
Post a link to the library.
It's this one: