Thread: const vector<> &a vs vector<> const &a

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    34

    const vector<> &a vs vector<> const &a

    is
    void Show_list( const std::vector<int> &List);
    equal to
    void Show_list( std::vector<int>const &List);
    or not?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If you mean
    void Show_list( const std::vector<int> & List);
    void Show_list( std::vector<int> const & List);
    then yes.
    (Note the space between std::vector<int> and const.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    34
    i try this
    void Show_list( std::vector<int>const & List);
    and compile with no error
    you mean its different from
    void Show_list( std::vector<int> const & List);
    ?

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Upon further testing, it would seem that compilers do accept both syntaxes. Actually, I did not know that, since I have never tried nor looked closely at such code.
    Still, whitespace is a good thing, so I would put a space there.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    With a few exceptions related to the preprocessor, white space in C++ is only significant for token separation. And ">const" is already two tokens, whether there's a space there or not, because symbols and letters never combine.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

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. Replies: 7
    Last Post: 04-28-2008, 09:20 AM
  5. Mutable members in const member functions still const
    By ripper079 in forum C++ Programming
    Replies: 3
    Last Post: 10-23-2002, 08:56 AM