Specializing Template Functions
Posted on 2010-09-02
I'm having a strange problem with templates again. So, I know that I can take a template function, say:
template <typename T>
void foo(T val)
//Do whatever with val of type T.
and that I can specialize it with:
void foo<bool>(bool val)
//Do whatever with specific type bool.
My problem is in a current project I did this and I'm getting:
-invalid explicit specialization before > token.
-explicit specialization in non-namespace scope "class myclassname".
-invalid member function declaration.
I tailored the class name but that's the exact output.
The project uses namespaces, but the current file is not in a namespace. It works fine as is (and it's using a template function). It breaks when adding the specialization for the funciton. I was originally trying to use a datatype which was defined in another namespace, but the same error occurs even if I just try bool, so I don't think that's the issue.
Oh, and my template brackets <> definitely line up despite the sound of the first error message. Any ideas of what I'm messing up?
Thanks in advance!