The GPIO class had, presumably, been created behind the scenes as many other classes will rely on it. The documentation explained how to get a reference to the existing object. It would not make much sense to have many instances of a GPIO object as there is only one set of IO ports.
From the class documentation
To instantiate this class:
// by pointer
CQEGpioInt *pio = CQEGpioInt::GetPtr();
// or by reference
CQEGpioInt &io = CQEGpioInt::GetRef();
The CSonar class, as you discovered, has to be instantiated. You could of course have more than one sonar connected using different ports, you would need a new instance for each one. Again, from the documentation.
CSonar::CSonar ( unsigned int inputPort,
unsigned int outputPort
Constructor for a sonar module.
inputPort the digital port number of the “INPUT” connector of the sonar module. Can be 0 through 15 corresponding to digital connector 1 through 16, respectively.
outputPort the digital port number of the “OUTPUT” connector of the sonar module. Can be 0 through 15 corresponding to digital connector 1 through 16, respectively.
If you did have several sonars, there is another class used for managing them all, presumably so that they did not send their “pings” at the same time.
Constructor & Destructor Documentation
CSonarController::CSonarController ( )
CSonarController::CSonarController ( unsigned int numSonar,
CSonar * sonarArray],
unsigned int fireIntervalMs
This constructor takes the necessary arguments to set up a working sonar array.
numSonar the number of sonars in the sonar array.
sonarArray an array of pointers to CSonar instantiations. The order of the CSonar pointers determines the firing order of the sonar array.
fireIntervalMs the amount of time in milliseconds to wait between subsequent sonar firings. This value should not be below 10 ms.
0 if success -1 if error.