Template Problem

template < typename T, int Size = 0 > void FileWriteVar ( ofstream* File, T Value )

NOW SOLVE IT.

... Not really. I never really practiced much with templates so I kinda' expected some sort of error to happen, but for some reason when I try to compile, I get the following error (MS VC++):

error C4519: default template arguments are only allowed on a class template


Now, I thought that you could use a default argument for any kind of template argument? This happens with all my other templates as well, but only those with default arguments. And no, this isn't a declaration. I know better than to try to do that with a template.
Last edited on
And the question is...?
I thought it would be obvious. What am I doing wrong?

Well, actually, there's also the badly-worded question of:

Now, I thought that you could use a default argument for any kind of template argument?
Last edited on
I think it's pretty evident that you can't, since the compiler is giving an error. I don't see how it could be clearer.
I can't find a reason for this in TC++PL. Actually, I find an example of the opposite:
1
2
template <class T,class C=Cmp<T> >
int compare(const String<T> &str1,const String<T> &str2)
I'm not saying that I don't understand the error. I'm saying that it goes against what I learned in the documentation, which is why I was asking about it.

The error is actually generated at the ending-bracket of the function definition. I don't know if that makes a difference, but I thought I might as well say it.

Actually, I find an example of the opposite:

Opposite of what?
Last edited on
Also, I'm kind of wondering...what is the point of having size as a template parameter in this case?
I had a reason before... I can't remember what it was. -_-' Good point. I'm beginning to think that some of my errors are just from stupidity. :| I began adding it as an argument instead, but stopped and put that back for some reason.
Topic archived. No new replies allowed.