Thread: const keyword.

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

    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.

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    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
    528
    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" ;

  4. #4
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    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 +

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, 04: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