Help: inline char const* const& max(char const* const &a, char const* const &b) 
Author Message
 Help: inline char const* const& max(char const* const &a, char const* const &b)

Hi, My Friends,

I'm reading a book about c++ . Following  is an example function in the
book.

//maximum of two C-String
inline char const* const& max(char const* const &a,     char const* const
&b)
{
 return strcmp(a,b)<0?b:a;

Quote:
}

There is no compile error on this function. But I can not understand it.

It return a pointer or a reference?  The  argumemts are pointer or
reference?  what do these const mean?

Who would like to explain it for me? I really appreciate.

Best regards

Larry



Sat, 26 Nov 2005 22:58:10 GMT  
 Help: inline char const* const& max(char const* const &a, char const* const &b)


Fri, 19 Jun 1992 00:00:00 GMT  
 Help: inline char const* const& max(char const* const &a, char const* const &b)

Quote:

> Hi, My Friends,

> I'm reading a book about c++ . Following  is an example function in the
> book.

> //maximum of two C-String
> inline char const* const& max(char const* const &a,     char const* const
> &b)
> {
>  return strcmp(a,b)<0?b:a;
> }

> There is no compile error on this function. But I can not understand it.

> It return a pointer or a reference?  The  argumemts are pointer or
> reference?  what do these const mean?

They are all references to pointers.    It's not particularly clear what the
author is trying to accomplish here.   Nothing is gained over passing by
value here (it actually might end up being less efficient).


Sat, 26 Nov 2005 23:02:25 GMT  
 Help: inline char const* const& max(char const* const &a, char const* const &b)
Indeed. It makes no sense to pass a pointer by reference (and have another
level of indirection) unless you're planning to change it, which is not the
case here. What book is that, out of curiosity?


Quote:




Quote:
> > Hi, My Friends,

> > I'm reading a book about c++ . Following  is an example function in the
> > book.

> > //maximum of two C-String
> > inline char const* const& max(char const* const &a,     char const*
const
> > &b)
> > {
> >  return strcmp(a,b)<0?b:a;
> > }

> > There is no compile error on this function. But I can not understand it.

> > It return a pointer or a reference?  The  argumemts are pointer or
> > reference?  what do these const mean?

> They are all references to pointers.    It's not particularly clear what
the
> author is trying to accomplish here.   Nothing is gained over passing by
> value here (it actually might end up being less efficient).



Sun, 27 Nov 2005 03:13:58 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. const char * vs char const *

2. const char *p == char const *p ?

3. Why not static const char * const __func__ ?

4. meaning of const char *const ?

5. Conversion const char* -> const unsigned short*

6. char** and const char** ...

7. va_arg(ap, const char *) = char*?

8. const char* to char[64]

9. char^ to const char* casting

10. const char ** incompatible with char ** (and vice versa)?

11. passing const char* to char* fails

12. const char* vs. char *

 

 
Powered by phpBB® Forum Software