[英]How do I pass a variable to a parent, but also return the output value? (C++)
I have two classes that are of the same type.我有两个相同类型的类。 One class A will be the parent to the other class B.
一个类 A 将是另一个类 B 的父类。
Class A and Class B have identical functions since they are the same type. A 类和 B 类具有相同的功能,因为它们是相同的类型。
I want to call from Class B a function from Class A that need a value and will return a void pointer.我想从 B 类调用一个来自 A 类的函数,该函数需要一个值并将返回一个空指针。
Class A
{
void * funct(inputInt);
}
Class B
{
protected:
Class* parent // here in header I set the parent class to it during construction
////
void* callFunction(int value)
{
return this->parent.funct(value);
}
}
How do I get something like this to work?我怎样才能让这样的事情发挥作用?
To answer your question the syntax for calling through a pointer is ->
and is a feature of the pointer parent
not on the return
statement.要回答您的问题,通过指针调用的语法是
->
并且是不在return
语句中的指针parent
的特征。 Your fixed line should look like this:您的固定线路应如下所示:
return parent->funct(value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.