Question with the "template <>"

I need help to know what the "template <>" code is for, I have been searching the internet for several weeks and I have not found anything about it. I found this code in a library that I would love to study to get some algorithms that I need in my project. But I need to know what is the purpose of that code to keep moving forward.

The code:

template<byte chipCount, typename ShiftType>
class _ShiftIn {
private:
byte ploadPin;
byte clockEnablePin;
byte dataPin;
byte clockPin;

const uint16_t dataWidth;
uint8_t pulseWidth;

ShiftType lastState;
ShiftType currentState;
public:
etc...

And I also need to know what this "ShiftType lastState; ShiftType currentState;" does, because it doesnt have an "=" sign or something similar.

Thanks!

Arduino uses standard C++, so you'll be more successful googling for "C++ template" than "Arduino template".

http://www.cplusplus.com/doc/tutorial/functions2/#templates
http://www.cplusplus.com/doc/tutorial/templates/#class_templates

Templates allow you to parameterize the data types used in classes and functions. For example, if you create a "list" class, you might want to reuse the same code for lists of floats, lists of Servos, lists of integers, lists of lists, etc. In that case, you create a template class so you can write list<float>, list<Servo>, list<int>, list<list<int>>, etc.

You can also use values as template parameters, such as chipCount in your example. This is useful to create arrays with configurable sizes.
The template parameter becomes part of the type, so it must be a compile-time constant.

The easiest example that demonstrates this is a simple array wrapper:

template <class Type, size_t Size>
struct ArrayWrapper {
  Type data[Size];
};

ArrayWrapper<int, 3> a = {{ 1, 2, 3 }};
ArrayWrapper<float, 2> b = {{ 0.1, 0.2 }};

You can reuse the array wrapper for arrays of all kinds of types of elements, and with any size.

ShiftType lastState; is a member variable declaration: ShiftType is the type, and lastState is the variable name. Compare it to int myInteger.

Pieter

Wow, thank you very much, at first I did not understand what you were saying, but when looking at all my complete code, I saw that everything made sense, THANK YOU VERY MUCH! Now I can move forward with my project