C++: Elements just below the constructor call of a class

Asked

Viewed 40 times

0

In my teacher’s code, he passed the following class template, with the constructor defined below:

template<typename T>
class CircularBuffer {
    std::vector<T> _elements;
    size_t _first, _n;
public:
    CircularBuffer(size_t n);
    void push(T v);
    T front() const;
    void pop();
    size_t size() const;
};

template<typename T>
CircularBuffer<T>::CircularBuffer(size_t n)
    : _elements(n), _first(0), _n(0) //?
{
}

I would like to understand what is and the usefulness of the line of code I marked with a comment and question mark

  • 2

    That? https://answall.com/q/169175/101

1 answer

1


The class attributes _first and _n are being initialized with the value 0.

The attribute _elements, it is a std::vector and is being built with initial size n, through one of its non-standard builders.

All this happens before the execution of the CircularBuffer and in the order in which they were specified.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.