What kind of C++ code is this?

I have this peace of C++ code:

cbuf::cbuf(size_t size) :
    next(NULL), _size(size), 
    _buf(new char[size]), 
    _bufend(_buf + size), 
    _begin(_buf), 
    _end(_begin) {
}

It looks like some kind of delegate, it does compile but does not create a working program.
I'm not familiar with this kind of programming, how do I change it so that is works?

that's a member initializer list for a constructor of the cbuf class (that you should have somewhere)

it's somewhat the same as

 cbuf::cbuf(size_t size) {
  next = NULL;
  _size = size; 
  _buf = new char[size];
  _bufend = _buf + size; 
  _begin = _buf;
  _end = _begin;
}

but in a way that is better if you need to subclass

can't answer your question if we don't have context though...

A less cryptic (and less pedantic) explanation: When do we use Initializer List in C++? - GeeksforGeeks

did not feel (or at least did not mean to provide)my answer was pedantic if you mean this negatively.

Not directed at you at all. I just find https://en.cppreference.com/ to be highly pedantic and more concerned with formalisms of the C++ language specification than it is with helping people understand and use the features.

OK

well it's focused more on the specification (the reference as the name imply) than educating... so indeed may be not the best didactic link I could have posted

Thanks all; J-M-L explains it well enough for me.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.