Thread: Dereferencing begin() for an empty STL vector

  1. #1
    Registered User
    Join Date
    Feb 2008
    Location
    Philadelphia, PA
    Posts
    2

    Dereferencing begin() for an empty STL vector

    Hi:

    I would like to know if it is safe to do something like the following:

    std::vector<int> arr;
    int* arrPtr = &(*arr.begin());

    I know that it is a valid thing to do if arr is not empty. I am not so sure about the case when arr is empty.

    Any help would be greatly appreciated.

    Thanks.

    Rahul

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Not safe.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vector in c++ stl
    By dpp in forum C++ Programming
    Replies: 43
    Last Post: 05-12-2009, 10:25 AM
  2. Vector class -STL lib
    By nishkarsh in forum C++ Programming
    Replies: 4
    Last Post: 08-31-2008, 09:27 PM
  3. Corrupted STL vector?
    By Hunter2 in forum C++ Programming
    Replies: 1
    Last Post: 08-21-2002, 11:18 AM
  4. mistake in tutorial re: stl vector
    By ygfperson in forum C++ Programming
    Replies: 4
    Last Post: 04-20-2002, 11:50 AM
  5. stl vector class
    By ygfperson in forum C++ Programming
    Replies: 3
    Last Post: 04-17-2002, 12:00 AM