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

孙华明 sunhm at neusoft.com
Wed Jul 19 17:16:45 CST 2006


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. 
-----------------------------------------------------------------------------------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codingnow.com/pipermail/cpp/attachments/20060719/0711a3a7/attachment.html


More information about the Cpp mailing list