Re: Need help with templates and VC6
??? wrote:
Hello!
I've written some code that uses member template functions, and it won't
compile with VC6 (or eVC4 which we really are using). The smallest
sample I can create that illustrates the problem is the following:
class Dep
{
public:
template<class T>
void Add()
{}
};
int main()
{
Dep dep;
dep.Add<int>();
return 0;
}
The compiler is unable to compile dep.Add<int>() (error C2062: type
'int' unexpected). I would like some help in finding a workaround. How
can I call Dep::Add and pass it a template type? I would be grateful for
any feedback!
Thanks in advance!
This is an unusual use of template function. If you let the compiler deduce the
type from the argument, I think it would work, as long as you define the method
inside the class definition (as you did). This last requirement if for VC6.
class Dep
{
public:
template<class T>
void Add(const T& t)
{}
};
int main()
{
Dep dep;
int n = 6;
dep.Add(n);
return 0;
}
[I don't have VC6 on this machine to check, but I'm sure I have done this
successfully.]
--
David Wilkinson
Visual C++ MVP