TITLE: const and template parameters (Newsgroups: comp.lang.c++.moderated,comp.lang.c++,comp.std.c++, 22 Mar 97) SILVERMAN: Greg Silverman > template > class A { > public: > void g(const T& t) { } > }; > > int main() > { > A b; > const char* c = new char; > b.g(c); //(1) > } > > The compiler complains about lines (1). It says > Formal argument of type char* const & in call to A::g(char* > const&) is being passed const char*. > > Uh? Why does it think the argument type is a "char* const &". I declared > it as a "const char* &" through the template, but the compiler moved the > placement of the const type-specifier. Why? SZONYE: "Bradd W. Szonye" This is one of the reasons I recommend writing 'T const &' and 'T const *' instead of the equivalent but confusing 'const T &' et al. Now look at void g(T const & t); where T is 'char*' as in your example, then the declaration is void g(char * const & t); which is a reference to a constant pointer, not a reference to pointer to constant. What you need to do is specialize your template for pointer types: template A { public: void g(T const & tcr); }; template A { public: void g(T const * & tcpr); };