Two ways of doing it. One is totally inline as you're doing it (which isn't really the C++ way of doing it).
Code:
#include <wpilib.h>
class LimitSwitch
{
public:
LimitSwitch(UINT32 port) :
di(port)
{}
bool getState()
{
return di.Get() != 0;
}
private:
DigitalInput di;
};
Or split into cpp/h files. Here's LimitSwitch.h:
Code:
#ifndef __LIMITSWITCH_H
#define __LIMITSWITCH_H
class LimitSwitch
{
public:
LimitSwitch(UINT32 port);
bool getState();
private:
DigitalInput di;
};
#endif
And LimitSwitch.cpp:
Code:
#include <wpilib.h>
#include "LimitSwitch.h"
LimitSwitch::LimitSwitch(UINT32 port) :
di(port)
{}
bool LimitSwitch::getState()
{
return di.Get() != 0;
}