I'm struggling with templates. The following compiles for me just fine:
//foo.h
class foo {
public:
template <typename T>
void swap(T* values, uint8_t offset)
{
T swp = values[offset];
values[offset] = values[offset + 1];
values[offset + 1] = swp;
}
};
This does not:
//foo.h
class foo {
public:
template <typename T>
void swap(T* values, uint8_t offset);
};
//foo.cpp
template <typename T>
void foo::swap<T>(T* values, uint8_t offset)
{
T swp = values[offset];
values[offset] = values[offset + 1];
values[offset + 1] = swp;
}
I get the error message
error: function template partial specialization 'swap<T>' is not allowed
I don't know what that means so I'm unclear on how to proceed. Thanx in advance.