I am having problems with some aspects of general programming, as described in the book "C ++ Programming Language".
Section 24.2. "Algorithms and rise" presents a general algorithm for accumulating values in a sequence of objects (also known in other languages as reduction, bending, sum, totality):
template<typename Iter, typename Val>
Val sum(Iter first, Iter last)
{
Val s=0;
while(first!=last) {
s = s + *first;
++first;
}
return s;
}
This function template is designed to work with arbitrary types, such as arrays of double values or related lists of user types like this, which is presented in the following paragraph:
struct Node {
Node* next; int data;
};
Node* operator++(Node* p) {return p->next;}
int operator*(Node* p) {return p->data;}
Node* end(Node* lst) {return nullptr;}
"sum", ++ * Node*. , . (MSVC GCC), :
'Node* operator++(Node*)' must have an argument of class or enumerated type
'int operator*(Node*)' must have an argument of class or enumerated type
- ?
?