I have 2 classes CVKinectWrapper.cpp and main.cpp. In the CVKinectWrapper, in the bool CVKinectWrapper::update(){ ... i have a variable XnSkeletonJointPosition righthand; I would like to access this variable in the main.cpp class. therefor i have created a
`void CVKinectWrapper::getRightHand(XnSkeletonJointPosition *righthand){
//*righthand = righthand;
righthand->copyTo(*righthand);
}`
The direct assignment doesn’t work, i get this error = ‘No match for ‘operator=’ in*righthand=righthand‘.
The copyTo doesnt work because the datatype of righthand hasn’t got this method.
For extra info :
This is how i access the wrapper in the main class = CVKinectWrapper *wrapper = CVKinectWrapper::getInstance();
wrapper->getRightHand(XnSkeletonJointPosition *righthand)
My question now is how can i access the righthand variable from the CVKinectWrapper in the main class.
This is probably a very basic question but i’m rather new to c++.
Thanks in advance.
When asking about compiler errors, it is usually a good idea to provide the exact error message, which in this case it probably states what the types of the two arguments are. At any rate, I think I can guess what the problems are.
You mention that you have a variable named
righthand, which I assume is actually a member of the class, and you want to copy the value to a different variable passed to the functiongetRightHand. Now the problem is that the argument of the function has the same name as the member, and it is shadowing it. InsidegetRightHand, the identifierrighthandrefers to the argument, not to the member. You can solve this by either changing the name of the argument or qualifying the access to the member:*righthand = this->righthand;As of the particular error message, the operation
*righthand = righthand;literally means assign the value of the pointerrighthand(argument to the function) to the object that it points, which does not make much sense. From a design point of view, the function as it is is quite un-idiomatic in C++, and should probably be replaced by:And the caller would do: