2

I'm working with Intel's PCSDK, there's a part I don't syntactically understand from a sample where the constructor of an abstract class is overridden. Specifically, this line:

GesturePipeline (void):UtilPipeline(),m_render(L"Gesture Viewer") {
EnableGesture();
}

What does the comma between UtilPipeline() and m_render mean? Here's the entire code for context:

#include "util_pipeline.h"
#include "gesture_render.h"
#include "pxcgesture.h"
class GesturePipeline: public UtilPipeline {
public:
GesturePipeline (void):UtilPipeline(),m_render(L"Gesture Viewer") {
EnableGesture();
}
virtual void PXCAPI OnGesture(PXCGesture::Gesture *data) {
if (data->active) m_gdata = (*data);
}
virtual void PXCAPI OnAlert(PXCGesture::Alert *data) {
switch (data->label) {
case PXCGesture::Alert::LABEL_FOV_TOP:
wprintf_s(L"******** Alert: Hand touches the TOP boundary!\n");
break;
case PXCGesture::Alert::LABEL_FOV_BOTTOM:
wprintf_s(L"******** Alert: Hand touches the BOTTOM boundary!\n");
break;
case PXCGesture::Alert::LABEL_FOV_LEFT:
wprintf_s(L"******** Alert: Hand touches the LEFT boundary!\n");
break;
case PXCGesture::Alert::LABEL_FOV_RIGHT:
wprintf_s(L"******** Alert: Hand touches the RIGHT boundary!\n");
break;
}
}
virtual bool OnNewFrame(void) {
return m_render.RenderFrame(QueryImage(PXCImage::IMAGE_TYPE_DEPTH),
QueryGesture(), &m_gdata);
}
protected:
GestureRender m_render;
PXCGesture::Gesture m_gdata;
};
Mike
  • 825
  • 3
  • 12
  • 30

5 Answers5

1

It's an initializer list which initializes the base class and a member variable:

GesturePipeline (void) // constructor signature
  : UtilPipeline(), // initialize base class
    m_render(L"Gesture Viewer") // initialize member m_render from GesturePipeline
{
    EnableGesture();
}
Daniel Frey
  • 55,810
  • 13
  • 122
  • 180
  • Why does `m_render` need to be initialized this way? – Mike Oct 30 '13 at 21:15
  • 1
    @Mike There are several reasons why something must be initialized in the initializer list: 1) Because it's a reference 2) Because it can not be default-initialized 3) Because the member variable is declared `const`. In your case I'd think it's probably 2). Of course it might just be used because it's more efficient and it's considered preferable by many, even if default-construction and an assignment later would be possible. – Daniel Frey Oct 30 '13 at 21:18
1

It's the member initializer list.

erenon
  • 18,838
  • 2
  • 61
  • 93
1

That's the constructor's initialiser list, used to specify how to initialise base sub-objects and data members before the constructor body begins.

This one value-initialises the base sub-object, then initialises the m_render member by passing a string to its constructor. The other data member is default-initialised, since it doesn't appear in the list.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
1

It's a member initializer list.

GesturePipeline (void):UtilPipeline(),m_render(L"Gesture Viewer") {
EnableGesture();
}

first initializes the base class with it's default constructor UtilPipeline then initializes m_render with m_render(L"Gesture Viewer"). Lastly it enters the function body and executes EnableGesture().

AliciaBytes
  • 7,300
  • 6
  • 36
  • 47
1

It is an initialization list. You are initializing that element in the class. Quick tutorial. The comma is separating the elements that you are initializing. It is calling the base constructor and then initializing its own elements.

Benjamin Trent
  • 7,378
  • 3
  • 31
  • 41