M
mike b
Hello everyone, thanks in advance for your help. I'm new to C++
templates and have run into some issues using member function
templates. I have a shared library containing templates that I'm
trying to use from an executable, compile using gcc 4.1.2. Everything
works fine until I try specializing one of the static member function
templates in a non-template class. I have a feeling I'm messing up
something obvious so before I post a bunch of code does the following
look correct? Thanks.
--- Shared Library (Arrays.h) ---
namespace example {
class Arrays {
public:
template<class T> static int compareItems(T *a1, T *a2, int length);
protected:
Arrays() {};
};
template<class T> int Arrays::compareItems(T *a1, T *a2, int length) {
printf("Calling generic function.\n");
return 1;
}
template<> int Arrays::compareItems<char>(char *a1, char *a2, int
length) {
printf("Calling char specialization.\n");
return 0;
}
}
templates and have run into some issues using member function
templates. I have a shared library containing templates that I'm
trying to use from an executable, compile using gcc 4.1.2. Everything
works fine until I try specializing one of the static member function
templates in a non-template class. I have a feeling I'm messing up
something obvious so before I post a bunch of code does the following
look correct? Thanks.
--- Shared Library (Arrays.h) ---
namespace example {
class Arrays {
public:
template<class T> static int compareItems(T *a1, T *a2, int length);
protected:
Arrays() {};
};
template<class T> int Arrays::compareItems(T *a1, T *a2, int length) {
printf("Calling generic function.\n");
return 1;
}
template<> int Arrays::compareItems<char>(char *a1, char *a2, int
length) {
printf("Calling char specialization.\n");
return 0;
}
}