defining methods of template class outside it

Let's say i want to define a method of a Stack class outside it :

I was thinking of :
1
2
3
4
5
6
7
8
9
10
11
template <typename T, typename Container = std::vector<T>>
class Stack {
    // ...
};

template <typename T, typename Container = std::vector<T>>
Stack<T, Container>::value_type
Stack<T, Container>::pop()
{
    // ...
}


And as u can see, it is terribly long and cumbersome.

Is there any way to shorten it ?

I'm thinking of something like :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// class stack

namespace
{
    // I think this part was messed up
    template <typename T,
          typename Container = std::vector<T>>
    using Stack_ = Stack<T, Container>;

    using typename Stack_::value_type
    using typename Stack_::size_type;
    using typename Stack_::reference;
    using typename Stack_::const_reference;
}

value_type Stack_::pop()
{
    // ...
}

but the compiler throws errors :

Stack.hpp:45:20: error: 'template<class T, class Container> using Stack_ = Stack
<T, Container>' used without template parameters
using typename Stack_::value_type
^
Last edited on
I think you can at least remove the default template argument when defining the functions.
1
2
3
4
5
6
template <typename T, typename Container>
Stack<T, Container>::value_type
Stack<T, Container>::pop()
{
    // ...
}
Topic archived. No new replies allowed.