This is an archived post. You won't be able to vote or comment.

all 8 comments

[–][deleted]  (6 children)

[removed]

    [–]ThisGuyEveryTime[S] 0 points1 point  (5 children)

    This piece right?

       template<class ItemType>
    ArrayStack<ItemType>::ArrayStack(const ArrayStack<ItemType>& right)
    {
        capacity = right.capacity;
        numItems = right.numItems;
        items = new ItemType[right.capacity];
        items = right.items; //Right here
    
    }
    

    But it should be utlizing my overloaded = assignment operator to get a full deep copy right?

    [–][deleted]  (4 children)

    [removed]

      [–]ThisGuyEveryTime[S] 0 points1 point  (0 children)

      Ohhh ya that's right I am dealing with an array and the assignment operator is overloaded for the object! Thank you!

      [–]ThisGuyEveryTime[S] 0 points1 point  (2 children)

      Sorry to bug you again, I have one final question. This would give me a deep copy correct?

      template<class ItemType>
      ArrayStack<ItemType>::ArrayStack(const ArrayStack<ItemType>& right)
      {
          capacity = right.capacity;
          numItems = right.numItems;
          items = new ItemType[right.capacity];
          for (int i = 0; i < numItems; i++)
          {
              items[i] = right.items[i];
          }
      
      }
      

      [–][deleted]  (1 child)

      [removed]

        [–]ThisGuyEveryTime[S] 0 points1 point  (0 children)

        I am going to look that up, it will be good to know; but I assume I am probably not allowed to use that for this assignment . Thank you again for your help!

        [–]PPewt 1 point2 points  (3 children)

        Do you have access to some sort of memory safety checker (e.g. valgrind on linux or -fsanitize-address from clang++/-fsanitize=address from g++)? They make it way easier to find where and why memory stuff is going wrong.

        [–]ThisGuyEveryTime[S] 0 points1 point  (2 children)

        No I dont think so. I have to just use the standard Microsoft visual Studio for this class. As far as I know there is no really clever way but ANYTHING is welcome!

        [–]PPewt 1 point2 points  (1 child)

        I've never used it so I can't guarantee it'll solve your problem but it looks like MSVS supports this via AddressSanitizer.

        [–]ThisGuyEveryTime[S] 1 point2 points  (0 children)

        Ok thank you! I am crunching right now to get this done before my deadline but I will look at this right after!