I'm trying to control a Dynamixel motor using the C++ SDK and I would like to do this from a class if possible. I need two pointers to an object and one other object to be class member variables. I found How can I initialize C++ object member variables in the constructor? but while it discusses both pointers to objects and objects themselves I need a combination. The three members I need look like this (taken from the sample code):
dynamixel::PortHandler *portHandler = dynamixel::PortHandler::getPortHandler(DEVICENAME);
dynamixel::PacketHandler *packetHandler = dynamixel::PacketHandler::getPacketHandler(PROTOCOL_VERSION);
dynamixel::GroupSyncWrite groupSyncWrite(portHandler, packetHandler, ADDR_MX_GOAL_POSITION, LEN_MX_GOAL_POSITION);
The issue is the GroupSyncWrite object depends on the pointers above it and must be declared after the first two are, so something like this:
Foo::Foo() : groupSyncWrite(...)
{
porthandler = dynamixel::PortHandler::getPortHandler(DEVICENAME);
packetHandler = dynamixel::PacketHandler::getPacketHandler(PROTOCOL_VERSION);
}
doesn't seem to work since the groupSyncWrite constructor takes porthandler and packethandler as parameters.
If anyone knows how to do this or if it's not possible to implement it like this I would appreciate any help.
EDIT:
The question in a nutshell is how to initialize two object pointers in a constructor prior to an object initialization in the same constructor.
There is an object foo that requires two pointers to objects as parameters, bar *one, and baz *two. The object and pointers are all members of my class and need to be initialized in the constructor of the class. The problem was I did not know how to initialize the pointers in the format
Class::Class() : one() {}
such as can be done with non-pointer objects. @Matthieu's answer worked perfectly.