Hello,
I am having trouble with recognizing the syntax related to pointers and arrow operator.
In the body of the function const_iterator& operator++(), the code
current = current -> next;
confuses me because of unfamiliar usage of an arrow operator in that code. From my knowledge one can use -> when a pointer tries to call class functions. Both members (current and next) are pointers, and I don't know how an arrow operator can be used with two pointers like that.
My second question is that the meaning of the code
++(*this);
in the body of function const_iterator operator++(int).
Could you help me to answer four questions in the code below?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
usingnamespace std;
class foo{
public:
int *z;
int k = 3;
z = &k; // Q1. Why does this code show an error message?
foo *x;
foo *y;
y = y->x; // Q2. Why does this show an error message? Q3. What does y->k (a pointer -> a pointer) mean?
//Q4. What is the difference between int *z and foo *x?
};
Q1. Look at the types and remember that a pointer is its own type. Does this look like it will work?
Q2. What does y point to? What is y->x?
Q3. I already explained that operator.
Q4. Look at the types.
#include <iostream>
usingnamespace std;
class foo{
public:
int *z;int k = 3;
int *z = &k; // Q1. Why does this code show an error message?
foo *x;
foo *y;foo *y = y->x; // Q2. Why does this show an error message? Q3. What does y->k (a pointer -> a pointer) mean?
//Q4. What is the difference between int *z and foo *x?
};
It compiles (Note: only from c++11 on), but all pointer (except z) just contain garbage.
Q3. Another pointer (wherever x points to).
Q4. Like already stated: different types.