Hallo,
da hab ich mal eine Frage zu cpp Templates.
ich möchte mir eine CRC Berechnungsklasse bauen.
Alleine vom eingereichten CRC Model soll diese wissen ob sie CRC8/16/32
berechnen soll.
Also Templates!
Nur muss ich von einem Template auf verschiedene Variablen Templates
schließen und bisher hab ich nicht gefunden wie das gehen soll.
Hier mal als Code was ich will:
1 | template <class crcType>
|
2 | class CrcCalc
|
3 | {
|
4 |
|
5 | public:
|
6 |
|
7 | //! constructor to initalize object
|
8 | CrcCalc(crcType *p_crc);
|
9 |
|
10 | //! virtual destructor
|
11 | virtual ~CrcCalc();
|
12 |
|
13 | //! \brief calculates the CRC over the given block
|
14 | //! \param[in] p_data Pointer do data to be CRC calculated
|
15 | //! \param[in] bytes number of bytes to calculate over
|
16 | //! \return CRC checksum
|
17 | virtual crcWidth Block(void *p_data, uint32_t bytes);
|
18 |
|
19 | private:
|
20 |
|
21 | //! \brief variable that holds the CRC Model
|
22 | crcType *mp_crcType;
|
23 |
|
24 | //! Variable that holds internal CRC calculation data
|
25 | crcCalc m_crcImmediates;
|
26 |
|
27 | };
|
Also von "crcType" möchte ich auch auf "crcCalc" und "crcWidth"
schließen können.
crcType kann sein:
-struct crc8
-struct crc16
-struct crc32
crcWidth soll dann sein:
-uint8_t
-uint16_t
-uint32_t
Also wie wär das möglich?
Natürlich könnt ich jetzt schreiben:
template <class crcType, class crcCalc, class crcWidth>
Aber das will ich vermeiden.