xcode 没有可行的超载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8201076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:29:35  来源:igfitidea点击:

No viable overloaded

c++xcodeclassproperties

提问by Olivier_s_j

I have 2 classes CVKinectWrapper.cppand 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.cppclass. therefor i have created a

我有 2 个类CVKinectWrapper.cppmain.cpp。在 CVKinectWrapper 中,bool CVKinectWrapper::update(){ ...我有一个变量,XnSkeletonJointPosition righthand;我想在main.cpp类中访问这个变量。因此我创建了一个

`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.

直接赋值不起作用,我收到此错误 = ' No match for 'operator=' in*righthand=righthand'。copyTo 不起作用,因为 righthand 的数据类型没有这个方法。

For extra info :

如需额外信息:

This is how i access the wrapper in the main class = CVKinectWrapper *wrapper = CVKinectWrapper::getInstance();

这就是我在主类中访问包装器的方式 = 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.

我现在的问题是如何从主类中的 CVKinectWrapper 访问右手变量。

This is probably a very basic question but i'm rather new to c++. Thanks in advance.

这可能是一个非常基本的问题,但我对 C++ 比较陌生。提前致谢。

回答by David Rodríguez - dribeas

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 memberof the class, and you want to copy the value to a different variable passed to the function getRightHand. Now the problem is that the argument of the function has the same name as the member, and it is shadowingit. Inside getRightHand, the identifier righthandrefers 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;

您提到您有一个名为 的变量righthand,我假设它实际上是类的成员,并且您想将该值复制到传递给函数的不同变量中getRightHand。现在的问题是函数的参数与成员具有相同的名称,并且它遮蔽了它。在内部getRightHand,标识符righthand指的是参数,而不是成员。您可以通过更改参数名称或限定对成员的访问权限来解决此问题:*righthand = this->righthand;

As of the particular error message, the operation *righthand = righthand;literally means assign the value of the pointer righthand(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:

对于特定的错误消息,该操作的*righthand = righthand;字面意思是将指针righthand(函数的参数)的值分配给它指向的对象,这没有多大意义。从设计的角度来看,该函数在 C++ 中非常不惯用,可能应该替换为:

const XnSkeletonJointPosition& CVKinectWrapper::getRightHand() const {
  return righthand;
}

And the caller would do:

调用者会这样做:

XnSkeletonJointPosition res = wrapper.getRightHand();