class - C++ Stack Template SIGTRAP Error -


Start learning about stack templates and work on push function while participating in a problem whenever I resize I try to free the memory for The function works fine all the way until it reaches the maximum capacity, and then immediately goes into a series of error messages not actually picked by my debugger. The function is a header file with error, Also calls this function.

  #include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Sstream & gt; using namespace std; Template & lt; Class T & gt; Class MyStack {Private: T * Data; Int topVal; Int capacity; Public: MyStacks () {Capacity = 10; Top Val = 0; Data = new t [capability]; } ~ MyStack () {Delete} data; Data = 0; } Zero push (t); T pop (); T top (); Bull is full (); Boole is empty (); String to string (); }; Template & lt; Class T & gt; Zero mystacks & lt; T & gt; :: push (t value) {if (! IsFull ()) {data [++ topVal] = value; } And {capacity * = 2; T * HoldPret = New T [Capacity]; For (int i = 0; i & lt; = topVal; ++ i) holdpath [ii] = data [i]; [] Delete data; // This is where the error data is getting = holdPtr; Data [++ topVal] = value; }} Template & lt; Class T & gt; Bull Mystique & lt; T & gt; :: full () {if (topweight & lt; capability) return false; And come back to the truth; }  

Any help would be greatly appreciated.

Edit: The problem is resolved! Thanks for all the help!

Two (related) problems:

1) With an empty stack, top == 0 . But puts your push element in data [++ topVal] - i.e., data [1] . Data [0] is never used.

2) When top == 9 and capacity == 10 , your isFull () return false and tries to store your push in data [10] which is outside

besides, your Push must be either from the value const context (or if you are using C ++ 11) std :: move to use


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -