Topic: ? Passing "hello" to const char* const&


Author: zhou@daldd.sc.ti.com (Tonghang Zhou)
Date: 13 Jan 1995 21:18:32 GMT
Raw View
 I have a senario:

  void foo(const char* const &);

  main()
  {
   foo("Hello");
  }

 g++ (v2.6.3) says the call of foo is an error because
 "Hello" is char[6] and can not be converted to const char* const&.
 Yet foo((char*)"Hello") is OK.

 Why is this? ARM seems to say that const T& will accept any thing
 T does. It seems then that const char* const& should accept any
 thing that const char* does, and const char* certainly accept
 "Hello".

 The situation comes up in using a template:
  template<class T> struct X { void foo(const T&); };
 and
  X<const char*>;

 BTW, there is no error if foo were declared to take
  const char* const
 But this hardly seems relevent.

 Please send your reply to me alos if you post a followup. Thanks.
--
 Regards, Tonghang
________________________________________________________________________________
Tonghang Zhou ("Zhou" is pronounced "Joe")
zhou@daLdd.sc.ti.com, W:(214)997-3933, H:(214)458-7565, IMS ID THZH, M/S 8316