|
|
*_Dest = *_First;
|
|
1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(127): error C2244: 'list<Elem>::iterator::operator ++': unable to match function definition to an existing declaration 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(126): note: see declaration of 'list<Elem>::iterator::operator ++' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(127): note: definition 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(127): note: 'auto list<Elem>::iterator::operator ++(void)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(127): note: existing declarations 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(127): note: 'auto list<Elem>::iterator::operator ++(int)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(127): note: 'auto &list<Elem>::iterator::operator ++(void)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(137): error C2244: 'list<Elem>::iterator::operator --': unable to match function definition to an existing declaration 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(136): note: see declaration of 'list<Elem>::iterator::operator --' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(137): note: definition 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(137): note: 'auto list<Elem>::iterator::operator --(void)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(137): note: existing declarations 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(137): note: 'auto list<Elem>::iterator::operator --(int)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(137): note: 'auto &list<Elem>::iterator::operator --(void)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(147): error C2244: 'list<Elem>::const_iterator::operator ++': unable to match function definition to an existing declaration 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(146): note: see declaration of 'list<Elem>::const_iterator::operator ++' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(147): note: definition 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(147): note: 'auto list<Elem>::const_iterator::operator ++(void)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(147): note: existing declarations 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(147): note: 'auto list<Elem>::const_iterator::operator ++(const int)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(147): note: 'auto &list<Elem>::const_iterator::operator ++(void)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(157): error C2244: 'list<Elem>::const_iterator::operator --': unable to match function definition to an existing declaration 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(156): note: see declaration of 'list<Elem>::const_iterator::operator --' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(157): note: definition 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(157): note: 'auto list<Elem>::const_iterator::operator --(void)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(157): note: existing declarations 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(157): note: 'auto list<Elem>::const_iterator::operator --(const int)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(157): note: 'auto &list<Elem>::const_iterator::operator --(void)' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\main.cpp(51): error C3779: 'list<int>::iterator::operator ++': a function that returns 'auto' cannot be used before it is defined 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(32): note: see declaration of 'list<int>::iterator::operator ++' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\main.cpp(51): error C2088: '++': illegal for class 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\main.cpp(58): error C3779: 'list<int>::iterator::operator ++': a function that returns 'auto' cannot be used before it is defined 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(32): note: see declaration of 'list<int>::iterator::operator ++' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\main.cpp(58): error C2088: '++': illegal for class 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\main.cpp(65): error C3779: 'list<int>::iterator::operator ++': a function that returns 'auto' cannot be used before it is defined 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\list.h(32): note: see declaration of 'list<int>::iterator::operator ++' 1>c:\users\osman\programming\visual_studio_2017\projects\programming_principles_practice_using_c++\real_linked_list\real_linked_list\main.cpp(65): error C2088: '++': illegal for class |
list(std::initializer_list<Elem> lst)
after those functions inside the class definition? And is that constructor fine now?
But anyway, for the parameters of the member functions, the typename is only needed because you are referring to it in a way which is dependent on the template parameters. If you remember that the class name is always injected into a class, even a template class, and any unqualified lookup will do a non dependent lookup on the current class name, then simply using:
will work. The return type is different though. The compiler doesn't do any looking ahead, so while it is reading the function declaration, it doesn't know what class, if any, it is a member of, so the unqualified lookup that was used with the parameters doesn't work, so while it is to the left of the function name then it will always require typename. There are two ways in which you can deal with this. One of these needs C++11 and the other needs C++14. The first is return type deduction, this is the C++14 feature:
The compiler will deduce the return type and so you won't need to give the type, meaning you won't have to use typename. The second is the trailing return type, this is the C++11 feature:
Because the return type is specified after the function name in this case, the compiler knows what class it can use to lookup unqualified names and so you don't need to use a template type name dependent way of looking up the name, this means you don't need to use typename. So basically, if you are referring to members of your class, then you can avoid typename if you use the fact that unqualified names will look in the class associated with the member function. |
|
|
|
|
curr->succ
being nullptr in the ++ operator functions?
|
|
The example in the book said to make it insert after the node pointed to by the passed in iterator. It's Programming: Principles and Practice Using C++ 2nd Edition, by Bjarne Stroustrup. |
As for end(); I could just check if last is nullptr, right? |
But how do I allow it to be able to decrement from the end iterator? The standard library list's end() returns an iterator to "one-past-the-end", doesn't it? |
Updated operator ++ and -- code: |
If I can't access first in the iterator class, though, how come the compiler doesn't give an error when I use begin()? |
|
|
12. Complete the definition of list from §20.4.1–2 and get the high() example to run. Allocate a Link to represent one past the end. 13. We don’t really need a “real” one-past-the-end Link for a list . Modify your solution to the previous exercise to use 0 to represent a pointer to the (nonexistent) one-past-the-end Link ( list<Elem>::end() ); that way, the size of an empty list can be equal to the size of a single pointer. |
new Link<Elem>(last->succ)
be fine, or does that not make sense?
In the ++ and -- operators, would it be better to get an iterator to begin() and end() (once I've fixed end())? |
As for what I said about last in relation to end(): |
I could allocate a node to represent the one-past-the-end node and assign 0 to it. Like it says in the book in these two exercises: |
If I do allocate a Link to represent the one-past-the-end node, what should I initialize it as (if I don't set it to 0)? |
Would new Link<Elem>(last->succ) be fine, or does that not make sense? |