Thread: Pointer Elements & STL Containers :: STL

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Pointer Elements & STL Containers :: STL

    Hi.

    Do delete STL functions such as remove() and erase() calls a class destructor if the element is a pointer to an object? For example, consider a vector of pointers to ClassX objects and a list of pointers to ClassX objects..

    Code:
    std::vector<ClassX *> sTextVec;
    
    ClassX *pCX;
    
    sTextVec.push_back(pCX);
    ...
    // Now you need to deallocate memory from pText.
    // Do functions such as remove() and erase() call ClassX 
    // destructor, or do you have to delete them explicitly?
    Thanks,
    Kuphryn

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    No, you have to delete them. This makes sense since
    vector must handle non-pointers calling delete on a
    nonpointer variable will cause problems.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    Good point.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structures, Pointer Elements, and Dereferencing
    By cyreon in forum C Programming
    Replies: 3
    Last Post: 05-22-2009, 11:05 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  4. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  5. Pointer of arrays - how do I access their elements?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-11-2001, 11:28 PM