const keyword.

This is a discussion on const keyword. within the C++ Programming forums, part of the General Programming Boards category; I can across this definition which makes me think that maybe I do not really understand the const keyword,..otherwise I ...

  1. #1
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    107

    const keyword.

    I can across this definition which makes me think that maybe I do not really understand the const keyword,..otherwise I do not understand why this definition cannot compile.
    Code:
    const std::string exclam = "!";
    const std::string message = "Hello" + ", world" + exclam;
    Last edited by Aslaville; 06-25-2013 at 11:25 PM.
    In C++14 you just write "auto auto(auto auto) { auto; }".
    The compiler infers the rest from context.

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,185
    O_o

    String concatenation (`operator +') is not defined with tho dumb strings (`const char *').

    Soma

  3. #3
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    107
    Quote Originally Posted by phantomotap View Post
    O_o

    String concatenation (`operator +') is not defined with tho dumb strings (`const char *').

    Soma
    I don`t quite understand because this compiles:
    Code:
    const std::string message = "Hello" + exclam ;//+ ", world" ;
    In C++14 you just write "auto auto(auto auto) { auto; }".
    The compiler infers the rest from context.

  4. #4
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    107
    Quote Originally Posted by phantomotap View Post
    O_o

    String concatenation (`operator +') is not defined with tho dumb strings (`const char *').

    Soma
    Ooh I got it.I cannot concatenate two dumb strings using operator +
    In C++14 you just write "auto auto(auto auto) { auto; }".
    The compiler infers the rest from context.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-20-2011, 01:19 PM
  2. Replies: 3
    Last Post: 11-15-2009, 03:57 AM
  3. Replies: 1
    Last Post: 04-03-2009, 08:52 AM
  4. Usages of const keyword
    By @nthony in forum C Programming
    Replies: 2
    Last Post: 09-16-2007, 11:45 PM
  5. c++ Pointers and the const keyword
    By ncallaway in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2006, 05:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21