Hello everyone,
after searching Google for two hours I'm still totally confused about the following example of an handout.
What I don't understand is the part
class element *get_item();
class node *get_next();
1. Are get_item and get_next member functions?
2. If yes why are they not decelerated by node::get_item();
3. What is there type, or are they really pointers?
class element{
public:
string name;
};
class node{
private:
class element *item;
class node *next;
public:
node();
node(class node *n);
~node();
// member functions
class element *get_item();
class node *get_next();
int set_next(class node *n);
};
...
// member functions definition
class element *node::get_item(){
return item;
}
class node *node::get_next(){
return next;
}
1. yes.
2. You only need node:: when you are referring to the functions outside the class definition.
3. get_item() returns a pointer to an element and get_next() returns a pointer to a node. It's not necessary to have the class keyword in front of the return type like they do in the code.