A
A
aarifkhamdi2017-01-03 16:12:30
OOP
aarifkhamdi, 2017-01-03 16:12:30

How to get a reference to a structure in a class?

Task: in getfirst() return a reference to the structure pointed to by first or the value of first. Trying to do this causes a problem.
Issue: Syntax error (probably in function definition header). I tried all conceivable options (I think it's pointless to list them?)
I cut off everything superfluous in the program so that the problem area was immediately visible.
Help a student, please.

template <class T>
class storage
{
  struct storagestruct
  {
    T item;
    storagestruct* next = nullptr;
  };
private:
  storagestruct* first = nullptr;
public:
  storage<T>() {};
  virtual ~storage();

  storagestruct& getfirst();
};

template<class T>
storage<T>::storagestruct& storage<T>::getfirst()
{
  return *first;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nexeon, 2017-01-03
@aarifkhamdi

Try like this:

template<class T>
typename storage<T>::storagestruct& storage<T>::getfirst()
{
  return *first;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question