Quick question

Discussion in 'C++' started by parag_paul@hotmail.com, Nov 2, 2007.

  1. Guest

    Sorry for aksing too many today ,

    I have seen const char &strl;
    where you cannot change str.

    Is there a similar concept like,
    char* const str ;
    for references,

    char const &str;

    etc
    If not , what is the reason for being so.
    -Parag
     
    , Nov 2, 2007
    #1
    1. Advertising

  2. wrote:
    > Sorry for aksing too many today ,
    >
    > I have seen const char &strl;
    > where you cannot change str.


    You cannot change what 'str' refers to because it's 'const'.
    You cannot change 'str' itself because there is no syntax for
    that (since 'str' is a reference).

    > Is there a similar concept like,
    > char* const str ;
    > for references,
    >
    > char const &str;


    Huh? That's not the same. 'char' here is const. When you
    declare

    char* const str;

    'str' is const, not 'char'. 'char' there is actually non-const.

    > etc


    'etc' what?

    > If not , what is the reason for being so.


    What is it exactly you need to know?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Nov 2, 2007
    #2
    1. Advertising

  3. Brian Szmyd Guest

    On Fri, 02 Nov 2007 11:41:02 -0700, wrote:

    > Sorry for aksing too many today ,
    >
    > I have seen const char &strl;
    > where you cannot change str.
    >
    > Is there a similar concept like,
    > char* const str ;
    > for references,
    >
    > char const &str;
    >
    > etc
    > If not , what is the reason for being so. -Parag


    I think what you're looking for is: char& str const

    const always acts to the left, unless there is no left then to the right.

    const char* == char const * != char* const
     
    Brian Szmyd, Nov 2, 2007
    #3
  4. Brian Szmyd Guest

    On Fri, 02 Nov 2007 19:30:51 +0000, Brian Szmyd wrote:

    > On Fri, 02 Nov 2007 11:41:02 -0700, wrote:
    >
    > I think what you're looking for is: char& str const
    >
    > const always acts to the left, unless there is no left then to the
    > right.
    >
    > const char* == char const * != char* const


    Oops...I posted that too quickly. char& str const makes no sense, you
    const the type, not the name. str is never const, it's just a variable
    name. the type "char" or "char*" is what is const.
     
    Brian Szmyd, Nov 2, 2007
    #4
  5. Brian Szmyd wrote:
    > On Fri, 02 Nov 2007 19:30:51 +0000, Brian Szmyd wrote:
    >
    >> On Fri, 02 Nov 2007 11:41:02 -0700, wrote:
    >>
    >> I think what you're looking for is: char& str const
    >>
    >> const always acts to the left, unless there is no left then to the
    >> right.
    >>
    >> const char* == char const * != char* const

    >
    > Oops...I posted that too quickly. char& str const makes no sense, you
    > const the type, not the name. str is never const, it's just a
    > variable name. the type "char" or "char*" is what is const.


    Well, the syntax you were looking for is

    char & const str

    but it does not exists since references cannot have cv-qualifiers
    because they are not objects.

    The syntax (if it existed) would be just like

    char * const str

    (here 'str' is a constant pointer to [non-constant] char).

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Nov 2, 2007
    #5
  6. James Kanze Guest

    On Nov 2, 8:52 pm, "Victor Bazarov" <> wrote:

    [...]
    > Well, the syntax you were looking for is


    > char & const str


    > but it does not exists since references cannot have cv-qualifiers
    > because they are not objects.


    And of course, the reference itself is immutable anyway.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Nov 3, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jack
    Replies:
    1
    Views:
    903
  2. jack

    Quick perl question 2

    jack, Aug 25, 2003, in forum: Perl
    Replies:
    1
    Views:
    905
  3. Jorell

    Quick Question

    Jorell, Aug 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    313
    Jorell
    Aug 8, 2003
  4. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    658
    Iain Norman
    Feb 16, 2005
  5. JKop
    Replies:
    11
    Views:
    889
Loading...

Share This Page