J
jw
it crashes but why?thanks for the helps.
#include<vector>
#include<iostream>
using namespace std;
template<class Object>
class Stack{
private:
vector<Object>myVec;
int topOfStack;
public:
Stack()
{
topOfStack=-1;
}
void push(Object x)
{
if(topOfStack==myVec.size()-1) {myVec.resize(myVec.size()*3);}//if
stack is full resize it
myVec[++topOfStack]=x;
}
};
void main(){
Stack<int>m;
m.push(5);
m.push(10);
}
#include<vector>
#include<iostream>
using namespace std;
template<class Object>
class Stack{
private:
vector<Object>myVec;
int topOfStack;
public:
Stack()
{
topOfStack=-1;
}
void push(Object x)
{
if(topOfStack==myVec.size()-1) {myVec.resize(myVec.size()*3);}//if
stack is full resize it
myVec[++topOfStack]=x;
}
};
void main(){
Stack<int>m;
m.push(5);
m.push(10);
}