M
mathieu
Why is the following code causing duplicate definitions (gcc 4.2) when
including swapper.h in multiple files ?
Thanks
-Mathieu
--------swapper.h-----------
#ifndef swapper_h
#define swapper_h
class Swapper
{
public:
template <typename T> static T Swap(T val);
template <typename T>
static void SwapArray(T *array, unsigned int n)
{
for(unsigned int i = 0; i < n; ++i)
{
array = Swap<T>(array);
}
}
};
#include "swapper.txx"
#endif
--------swapper.txx-----------
#ifndef swapper_txx
#define swapper_txx
template <> uint16_t Swapper::Swap<uint16_t>(uint16_t val)
{
return bswap_16(val);
}
template <> uint32_t Swapper::Swap<uint32_t>(uint32_t val)
{
return bswap_32(val);
}
template <> uint64_t Swapper::Swap<uint64_t>(uint64_t val)
{
return bswap_64(val);
}
#endif
including swapper.h in multiple files ?
Thanks
-Mathieu
--------swapper.h-----------
#ifndef swapper_h
#define swapper_h
class Swapper
{
public:
template <typename T> static T Swap(T val);
template <typename T>
static void SwapArray(T *array, unsigned int n)
{
for(unsigned int i = 0; i < n; ++i)
{
array = Swap<T>(array);
}
}
};
#include "swapper.txx"
#endif
--------swapper.txx-----------
#ifndef swapper_txx
#define swapper_txx
template <> uint16_t Swapper::Swap<uint16_t>(uint16_t val)
{
return bswap_16(val);
}
template <> uint32_t Swapper::Swap<uint32_t>(uint32_t val)
{
return bswap_32(val);
}
template <> uint64_t Swapper::Swap<uint64_t>(uint64_t val)
{
return bswap_64(val);
}
#endif