2

I have a couple of syntax questions that I'm sure most people could answer but this is all foreign to me and I worked through a class tutorial but it left a few questions unanswered.

This code is the declaration line of a class function and inside the parenthesis are the values to be passed. correct?

void HwCounter_IVBNHSX_IMC::SetRegisterLocations(int bus, int ha, int chan, int counterNumber)  
{
_ha = ha;
_chan = chan;
_counterNumber = counterNumber;
_bus = bus;
}

In this example what does the additional semicolon at the end enable? Where would I be looking to see what the counterNumbers are associated with?

HwCounter_IVBNHSX_IMC::HwCounter_IVBNHSX_IMC(int hwType, const char* pName) : HwCounterBase(pName)
{
_counterNumber = 0;
_currentConfig = 0;
_hwType = hwType;
}

I'm unable to post the entire source code sorry and I know that makes it more difficult but any help would be appreciated.

kaminsknator
  • 1,135
  • 3
  • 15
  • 26

2 Answers2

2

This code is the declaration line of a class function and inside the parenthesis are the values to be passed. correct?

Yes, it is, being understood that the function has to be first declared inside the class.

In this example what does the additional semicolon at the end enable?

HwCounter_IVBNHSX_IMC::HwCounter_IVBNHSX_IMC(..) is a constructor for the class HwCounter_IVBNHSX_IMC.

The : is followed by a list of mem-initializer, a special form of initialization of data members and of the base class if necessary. For example HwCounterBase(pName) means that the data member (or the base class) HwCounterBase is intialized by calling its constructor with the value pName.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • More probably, `HwCounterBase` is the/a base class of `HwCounter_IVBNHSX_IMC`; `HwCounterBase(pName)` then calls the constructor of the base class and passes `pName` to it. – Murphy Jan 19 '16 at 22:55
1

This:

void HwCounter_IVBNHSX_IMC::SetRegisterLocations(int bus, int ha, int chan, int counterNumber)  
{
  ...
}

is the definition of a function. (The declaration is something else, and to learn the distinction you should start with a simpler example.) Its name is SetRegisterLocations, it is a member of the class HwCounter_IVBNHSX_IMC, it takes four arguments (all int), and it returns nothing (void).

This:

HwCounter_IVBNHSX_IMC::HwCounter_IVBNHSX_IMC(int hwType, const char* pName)
{
  ...
}

is similar, but it is a constructor. The name of the function is the same as the name of the function, and it has no return type (not even void).

This: HwCounter_IVBNHSX_IMC::HwCounter_IVBNHSX_IMC(int hwType, const char* pName) : HwCounterBase(pName) { ... }

is the same, but it has an initializer list (consisting of only one initializer) which sets the value (or calls the constructor) of a member variable (HwCounterBase).

Where would I be looking to see what the counterNumbers are associated with?

The rest of the code.

Beta
  • 96,650
  • 16
  • 149
  • 150