Given the following class template definitions
template<typename T>
class node{
private:
T& data;
shared_ptr<node<T>>& next;
public:
T& get_data(void);
shared_ptr<node<T>>& get_next (void);
public:
node(T&);
~node();
};
template<typename X>
class list{
private:
shared_ptr<X> head;
list(shared_ptr<X>&);
public:
shared_ptr<X>& get_head(void);
void set_head(shared_ptr<X>&);
public:
list();
~list();
public:
int size (void);
};
and the following corresponding method definitions
template<typename T>
shared_ptr<node<T>>& node<T>::get_next(void){
return(this->next);
}
template<typename X>
int list<X>::size (void){
auto h = this->head;
auto count = 0;
while(h){
++count;
h = h->get_next();
}
return count;
}
And the following code in main()
list<node<string>>menu;
auto num_menu_items = menu.size();
the following compiler error ensues:
In instantiation of "int list<X>::size() [with X = node<std::basic_string<char> >]":
error: "std::shared_ptr<node<std::basic_string<char> > >& node<std::basic_string<char> >::next" is private within this context
h = h->get_next();
~~~^~~~
note: declared private here
shared_ptr<node<T>>& next;
Complete source code can be accessed below:
Complete compiler log can be accessed below:
Appreciate your thoughts.