May 15, 2020 at 12:13pm May 15, 2020 at 12:13pm UTC
I am trying to implement a std::list-like doubly linked list and when defining a constructor I am coming across an error that I don't quite understand.
The stripped down code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
template <typename T>
class List
{
public :
template <typename InputIt, typename = std::_RequireInputIter<InputIt>>
List(InputIt first, InputIt last);
};
template <typename T>
template <typename InputIt, typename = std::_RequireInputIter<InputIt>>
List<T>::List(InputIt first, InputIt last)
{
// some code here
}
int main()
{
}
When trying to compile an error is thrown:
error: default argument for template parameter for class enclosing 'List<T>::List(InputIt, InputIt)' |
The error message is not clear for me, anyone to shine a light?
Thanks!!
Last edited on May 15, 2020 at 12:19pm May 15, 2020 at 12:19pm UTC
May 15, 2020 at 2:47pm May 15, 2020 at 2:47pm UTC
@highwayman
template <typename T>
is for List<T>
template <typename InputI...
is for List(InputIt first, InputIt last)
May 15, 2020 at 2:48pm May 15, 2020 at 2:48pm UTC
Ahhh wait I get it now ok cool.
May 15, 2020 at 2:59pm May 15, 2020 at 2:59pm UTC
Default arguments only belong in the declaration:
1 2 3 4 5 6
template <typename T>
template <typename InputIt, typename >
List<T>::List(InputIt first, InputIt last)
{
// some code here
}
Last edited on May 15, 2020 at 3:35pm May 15, 2020 at 3:35pm UTC
May 15, 2020 at 3:14pm May 15, 2020 at 3:14pm UTC
@mbozzi oh I see, Thanks
Is there any workaround for that?
Last edited on May 15, 2020 at 3:15pm May 15, 2020 at 3:15pm UTC