With shared_ptr, can custom destructor take multiple objects?

This is a discussion on With shared_ptr, can custom destructor take multiple objects? within the C++ Programming forums, part of the General Programming Boards category; Is there a way to pass multiple objects to the custom destructor for a shared_ptr? OR, can i pass an ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    184

    With shared_ptr, can custom destructor take multiple objects?

    Is there a way to pass multiple objects to the custom destructor for a shared_ptr? OR, can i pass an instance's function?

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Quote Originally Posted by 6tr6tr View Post
    Is there a way to pass multiple objects to the custom destructor for a shared_ptr? OR, can i pass an instance's function?
    Eh, what? That makes even less sense than usual.

    A shared_ptr doesn't have a "custom destructor," its destructor simply deletes the object being pointed to. If that object has a polymorphic destructor, then the proper destructor will be invoked. I can't make heads or tails of what you're asking.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    184
    Quote Originally Posted by brewbuck View Post
    Eh, what? That makes even less sense than usual.

    A shared_ptr doesn't have a "custom destructor," its destructor simply deletes the object being pointed to. If that object has a polymorphic destructor, then the proper destructor will be invoked. I can't make heads or tails of what you're asking.
    Sorry, I mean "custom deleter."

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Quote Originally Posted by 6tr6tr View Post
    Sorry, I mean "custom deleter."
    You can always make a "custom deleter" by overloading the delete operator for the class in question.

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    According to the documentation for smart_ptr
    Code:
    template<class Y, class D> shared_ptr(Y * p, D d);
    it takes a deletor object, and it looks like the destructor just calls: d(p);
    So you can create your custom deletor's constructor to take as many parameters as you want, just as long as the operator() function only takes 1 parameter which is the pointer to be deleted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 60
    Last Post: 12-20-2005, 11:36 PM
  2. Replies: 4
    Last Post: 06-18-2005, 03:26 PM
  3. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 03:41 AM
  4. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 11:01 AM
  5. multiple (ctime) struct tm* objects
    By cjschw in forum C++ Programming
    Replies: 3
    Last Post: 10-08-2003, 02:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21