-
Function Templates
Code:
template <typename OldType, typename NewType>
any & ChangeType()
{
placeholder * newcontent = new holder<NewType>(reinterpret_cast<NewType>(any_cast<OldType>(*this)));
std::swap(content,newcontent);
delete newcontent;
return *this;
}
Thats part of my class.
here's my main:
Code:
#include <any.hpp>
int main()
{
blah.ChangeType<int,char>();
}
And it says that it doesn't expect the int...
-
It seems that you are trying to declare a member function of a class as a template. Ive never seen this done myself, so this is just a guess, but you might try to template the entire class if possible, or declare your member function as static, or just overload the function instead of templating it.
-
Actually, I think your problem is in main. What is blah? I don't know, and my guess is that your compiler doesn't know either.
-
lol I forgot the put the rest of the code I was using... I only wanted to give the related lines.
there is a line like this:
"any blah = 1;"
-
I've had a similar problem before... it seems that my compiler doesn't like function templates a whole lot inside classes.
I tried doing it without prototyping and it worked last time... i.e. I get no errors if I make them pass the types, but thats not what I want.
Why won't VC++ 6.0 let me use a template this way? I know technically it should work...
-
Found a workaround using friend. thx anyway