I was writing some code for a project, and I was using a library named APA102. In this library, there is a class titled APA102
defined as follows,
template<uint8_t dataPin, uint8_t clockPin>
class APA102 : public APA102Base {
...
I am confused why anyone would use a template class to define a value that could have easily been passed as a class constructor parameter.
And to extend on my original question, I was attempting to create a class method that used this APA102
class as a parameter, but I was not able to define a parameter as this type if I tried to do as follows:
void someMethod(APA102<uint8_t, uint8_t> ¶m)
As I kept getting the error
error: type/value mismatch at argument 1 in template parameter list for 'template<unsigned char dataPin, unsigned char clockPin> class Pololu::APA102' virtual void someMethod(APA102<const uint8_t, const uint8_t> &ledStrip) = 0;
The only way I could have an APA102
object as a parameter was to define two uint8_t
values, and use those as the template parameters first. For example, this worked:
const uint8_t clockPin = 11;
const uint8_t dataPin = 12;
virtual void someMethod(APA102<clockPin, dataPin> &ledStrip) = 0;
Can anyone help me understand these template classes with predefined template parameters? Why did I get the error I did?