I have a function where 'T' can either be a queue or a stack. Currently for the function signature I have:
template <class T>
void foo(T<string> baa){
//do something
}
Within foo I want to call T.pop() but I cannot do so.
I then wrote two version of pop, one for a queue and one for a stack.
string bar(stack<string> & baa){
string t=baa.top();
baa.pop();
return t;
}
string bar(queue<string> & baa){
string t=baa.front();
baa.pop();
return t;
}
I then tried to do this but it wouldn't work. How am I supposed to do this?
template <class T>
void foo(T<string> baa){
//do something
string baz=bar(baa);
}
EDIT:I forgot that top() simply removes the top element. I have now edited the code fragment to reflect those changes. However it still isn't working.
T<string>? Wouldn'tTbe sufficient?pop()does?