Thread: erasing a dynamic allocatd object inside a stack template...,

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    142

    erasing a dynamic allocatd object inside a stack template...,

    hi,

    template <class T>
    class MyStack
    {
    stack<T *> m_Stack;
    public:
    void myPop()
    {
    T* ptr = m_Stack.top();
    delete ptr; // assertion error, block still in used??
    m_Stack.pop();
    }
    };

    i used this class this way..,
    MyStack.myPush(new Object());

    help? many thanks!

    EDIT: actually this thing works if i don't encapulsulate std::stack into another class,

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    void? why not? i don't need it's return value, i just want to delete the top most object,

    i made this class because the standard std::stack doesn't delete the object when you call upon it's pop function so i made this.
    Last edited by mickey; 10-26-2002 at 03:54 AM.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    uh.. wait, i do it like this,

    T* ptr = m_Stack.top();
    delete ptr; // i still have the reference?
    m_Stack.pop();


  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    oh i'm sorry i misinterpreted your post,

    anyway, i've also tried that but same assertion error, BLOCK_TYPE_IS_VALID(pHead->nBlockUse) ??

    thanks!

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    help?

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    hehe no problem, but i hope someone else there could help me,
    i also can't see why it's a problem since i'm just doing the same thing if i don't encapsulate to my own class the std::stack..,

    i can't either find the answer to my c++ primer and the c++ programming language,

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    help? anyone?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  2. What could be wrong about this template?
    By kromozom in forum C++ Programming
    Replies: 10
    Last Post: 12-27-2004, 01:15 AM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  4. HEap and stack, I'm confused
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-31-2002, 10:59 AM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM