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, 12:05 PM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  3. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 03:29 PM
  4. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 04:20 AM
  5. Pointer of arrays - how do I access their elements?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-12-2001, 12:28 AM
Website Security Test