If I have the following structure:
struct data1{
   uint8_t data;
} 
template <class T>
struct packetTXMaintenance{
   uint8_t start_byte;
   uint8_t byte_count;
   uint8_t address;
   T temp_parameter;
   uint8_t command_id;
 };
For example I can instantiate the struct like this:
packetTXMaintenance<data1> value;   
But it's possible to instantiate the struct without the template temp_parameter? (In some case I want the struct without the temp_parameter member, in other case with temp_parameter member with different type T)
You can specialize the struct for void as a template argument and in this implementation you can omit the member:
Just add this right after the declaration of your struct:
template <>
struct packetTXMaintenance <void>
{
   uint8_t start_byte;
   uint8_t byte_count;
   uint8_t address;
   uint8_t command_id;
};
So when you use packetTXMaintenance <void> variable then variable will not have the member, it's a totally different implementation.
Edit:
If you want the member to be with a different type T then you can just instantiate the struct with a different type: packetTXMaintenance<int>, in this case temp_parameter will have the type int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With