Hmm a strange one in VC2012 I can't seem to work out the syntax for passing a const pointer by const reference into a function of a templated class whose template argument is a non const pointer ie:
template<typename T> struct Foo { void Add( const T& Bar ) { printf(Bar); } }; void main() { Foo<char*> foo; const char* name = "FooBar"; foo.Add(name); // Causes error } So I've simplified my problem here but basically I want the argument to 'Add' to have a const T ie const char*. I've tried:
void Add( const (const T)& Bar ); typedef const T ConstT; void Add( const (ConstT)& Bar ); void Add( const typename std::add_const<T>::type& Bar ); None of which work. The exact error I'm getting is:
error C2664: 'Foo<T>::Add' : cannot convert parameter 1 from 'const char *' to 'char *const &' with [ T=char * ] Conversion loses qualifiers which I can see is correct but how do I solve it without const casting 'name' to be non const.