Assume you have a templated class like this:
template <typename type>
class Object {
using length_t = unsigned int;
template <length_t length>
void put(type (&)[length]);
};
and you declared a put(...) method in it like so.
How do you go about declaring that put(...) method outside the class?
Here's one approach someone might take:
/* ERROR: Doesn't match any declarations(?) */ template <typename type> template <typename Object<type>::length_t length> void Object<type>::put(type (&)[length]) {}but this leads to a peculiar error
error: no declaration matches 'void Object<type>::put(type (&)[length])' note: candidate is: template <class type> template <unsigned int length> void Object<type>::put(type (&)[length])Here's another way to declare the
put(...)method such that it works:/* SUCCESS: But `length_t` alias isn't used */ template <typename type> template <unsigned int length> void Object<type>::put(type (&)[length]) {}but the
length_ttype alias defined in theclassisn't used.
How does one get the first definition to work so as to keep the use of the class's features (like type aliases) consistent across its declaration & definitions, or is the second definition the only solution here?