Re: [cpp] 关于const char * const &

胡 玮 zorro0799 at hotmail.com
Wed Jul 19 17:36:41 CST 2006


应该是指针的引用,这个指针指向一个const,但我很奇怪const char *&不就行了,
为什么*&中间还要加个const,要知道引用只能初始化,从偏译器的角度看本身就是个
常量没有必要再加const,这样看起来很怪

>From: 孙华明 <sunhm at neusoft.com>
>Reply-To: C++ Discuss Group <cpp at codingnow.com>
>To: C++ Discuss Group <cpp at codingnow.com>
>Subject: Re: [cpp] 关于const char * const &
>Date: Wed, 19 Jul 2006 17:16:45 +0800
>
>const char* const& a;
>这个声明是什么意思啊?
>这么复杂!
>   ----- Original Message -----
>   From: ling
>   To: C++ Discuss Group
>   Sent: Wednesday, July 19, 2006 4:12 PM
>   Subject: Re: [cpp] 关于const char * const &
>
>
>   不好意思,我知道原因了,应该是头文件iostream中有一个同名的函数min.
>
>   ----- Original Message -----
>     From: ling
>     To: C++ Discuss Group
>     Sent: Wednesday, July 19, 2006 5:04 PM
>     Subject: [cpp] 关于const char * const &
>
>
>
>     请问下面代码的函数min和min1有什么区别啊。
>     为什么函数min取得的比较结果不对呢?另外如果数组a,b的声明
>     前面加上const的话,函数min取得的结果就对了。
>     函数min1不管有没有const都能得到正确的结果。
>
>     #include <cstring>
>     #include <iostream>
>     using namespace std;
>
>     const char* const& min(const char* const& a, const char* const& b)
>     {
>      cout << "a = " << a << endl;
>      cout << "b = " << b << endl;
>      return (strcmp(a, b) < 0) ? a : b;
>     }
>
>     const char* const min1(const char* const a, const char* const b)
>     {
>      return (strcmp(a, b) < 0) ? a : b;
>     }
>
>     int main()
>     {
>      char a[] = "123";
>      char b[] = "456";
>
>      cout << min(a, b) << endl;
>       cout << min1(a, b) << endl;
>     }
>
>
>----------------------------------------------------------------------------

>
>
>     _______________________________________________
>     Cpp mailing list
>     Cpp at codingnow.com
>     http://codingnow.com/mailman/listinfo/cpp
>
>
>
>------------------------------------------------------------------------------

>
>
>   _______________________________________________
>   Cpp mailing list
>   Cpp at codingnow.com
>   http://codingnow.com/mailman/listinfo/cpp
>
>
>----------------------------------------------------------------------------------------------

>Confidentiality Notice: The information contained in this e-mail and any 
accompanying attachment(s) is intended only for the use of the intended 
recipient and may be confidential and/or privileged of Neusoft Group Ltd., 
its subsidiaries and/or its affiliates. If any reader of this communication 
is not the intended recipient, unauthorized use, forwarding, printing, 
storing, disclosure or copying is strictly prohibited, and may be unlawful. 
If you have received this communication in error, please immediately notify 
the sender by return e-mail, and delete the original message and all copies 
from your system. Thank you.
>-----------------------------------------------------------------------------------------------

>


>_______________________________________________
>Cpp mailing list
>Cpp at codingnow.com
>http://codingnow.com/mailman/listinfo/cpp

_________________________________________________________________
享用世界上最大的电子邮件系统&# 8213; MSN Hotmail。  http://www.hotmail.com  



More information about the Cpp mailing list