Topic: Is this a legal template function? BC says yes. MSVC says no.
Author: robc@thinkman.com (Rob Chambers)
Date: 1995/08/26 Raw View
Hi! I've looked all through the ARM and I can't find a reason why I
shouldn't be able to do this:
11: template<class T>
12: inline void DeleteArray(T* &pat)
13: {
14: if (NULL != pat)
15: {
16: delete [] pat;
17: pat = NULL;
18: }
19: }
and call it like this:
30: double *pad = new double[10];
31: DeleteArray(pad);
When I compile this with Borland C++ 4.0, it works just fine. When I
compile it with MS Visual C++ 2.0 I get the following error:
test.cpp(31) : error C2607: 'initializing' : cannot implicitly
convert a 'double*' to a 'double**& ' that is not const
Who's right? Borland or Microsoft? Is it legal or not?
[[ Your code looks perfectly legal to me. I'd say it was a Microsoft bug.
- fjh (moderator). ]]
Thanks,
Rob Chambers
robc@thinkman.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]