![]() |
|
|
|
|
|||||||
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ftp zip files corruption | colesga | Shell Programming and Scripting | 3 | 08-02-2007 08:22 AM |
| *** glibc detected *** free(): invalid next size (normal): 0x0000000000503e70 *** | vbreddy | High Level Programming | 1 | 04-11-2006 09:18 AM |
| NTFS corruption under w2k but not under suse 9.2 | mickepe | Windows & DOS: Issues & Discussions | 4 | 08-05-2005 05:19 PM |
| data corruption with ftp transfer | malcom | UNIX for Advanced & Expert Users | 12 | 08-04-2003 04:38 AM |
| file corruption | shibz | UNIX for Advanced & Expert Users | 5 | 09-06-2002 08:56 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Use reference in your member function
The problem seems to be your member function definition:
MyStack operator + (MyStack); It should use a reference of MyStack as the argument as follows: MyStack operator + (MyStack&); Without the &, a copy of MyStack object is made and it contains a pointer to the private data member T* stackPtr. When the copy of the MyStack goes out of scope in the member function, the destructor of the MyStack object copy is called and the stackPtr is deleted. This also deletes the stackPtr of the original object because your class does not define a copy constructor to make a deep copy of the stackPtr. Then when your original object's destructor is called later, it does "delete [] stackPtr" again on an already deleted pointer. Thus the error appears. |
|||
| Google UNIX.COM |
| Forum Sponsor | ||
|
|
| Thread Tools | |
| Display Modes | |
|
|