I have some constants named like this:
template<int n> class usart {
private:
usart();
public:
enum class tx {};
enum class rx {};
enum class ck {};
};
template<> class usart<1> {
public:
enum class tx { A9 = gpio::A9, C4 = gpio::C4 };
enum class rx { A10 = gpio::A10, C5 = gpio::C5 };
enum class ck { A8 = gpio::A8 };
};
// two more of these
where gpio
is just a simple integer enum.
I'd like to enforce some type safety on my class in another file:
class USART {
public:
template<int N>
USART(typename usart<N>::tx pin_tx, typename usart<N>::rx pin_rx) {
//This signature enforces correct pins with types, doesn't it?
}
};
However, when I use this with
USART us = USART(usart<1>::tx::A9, usart<1>::rx::A10);
I get the error
error: expected ')' before 'pin_tx'
Why is this syntax illegal?
EDIT: typename
This now gives me this error when I try and instantiate the class:
error: no matching function for call to 'USART::USART(usart<1>::tx, usart<1>::rx)' note: template<int N> USART::USART(typename usart<N>::tx, typename usart<N>::rx) note: template argument deduction/substitution failed: note: couldn't deduce template parameter 'N'