0

I want to use the std::queue in an program. But later I may change to an other implementation of queues. I have a header with all my typedefs but typedef dont works for std::queue. Is there a way to have something simular to an typedef for std::queue?

Edit: I dont want a typedef for a specific type like this:

typedef std::queue<int> IntQueue;

I tryed this

template <class T>
typedef std::queue<T> Queue;
RoniPerson
  • 21
  • 4
  • what do u mean by typedef for std::queue, can u give an example – asmmo May 26 '20 at 11:06
  • You should include what doesn't work so we can tell you why it doesn't. `typedef` works fine for all types, including `std::queue` instances. – Quentin May 26 '20 at 11:06
  • Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please [edit] your question to show us a [mcve] of what you have tried, and tell us what problems it gives you. – Some programmer dude May 26 '20 at 11:06
  • Did you try using the typedef? Like really just `typedef std::queue queue`...? – KamilCuk May 26 '20 at 11:09
  • As for your problem, think of `typedef` like a variable declaration. If you would declare a variable using an `std::queue` of `int`, how would you declare it? Now try putting `typedef` before that variable declaration. – Some programmer dude May 26 '20 at 11:11
  • 2
    Lastly just a guess about your problem: You try to use the *template* `std::queue`. The problem is that it's not a type, it's a *template* for a type. `std::queue` is a type. If you want to create an alias for the template itself, you must do it as a `template` but have to be using `using` and not `typedef` (as in `template using queue_alias = std::queue;`) – Some programmer dude May 26 '20 at 11:12

1 Answers1

0
template <class T>
using Queue =  std::queue<T> ;

and then in main, you can use it as follows

int main() {
    Queue<int> q;
    q.push(3);
}
asmmo
  • 6,922
  • 1
  • 11
  • 25