Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 返回;仅具有无返回值_C++ - Fatal编程技术网

C++ 返回;仅具有无返回值

C++ 返回;仅具有无返回值,c++,C++,当有人编码时,这意味着什么: template <class T> void binaryTree<T>::in_order(Node <T>* node, void (*fun)(T&)) { if (node == NULL) return; //<-- what does this mean here inorder(node->left, fun); //<--

当有人编码时,这意味着什么:

 template <class T>
 void binaryTree<T>::in_order(Node <T>* node, void (*fun)(T&))
{
    if (node == NULL)   
            return;     //<-- what does this mean here

    inorder(node->left, fun);   //<-- how does this continue here
    f(node->data);
    inorder(node->right,fun);
}
模板
void二进制树::按顺序(Node*Node,void(*fun)(T&)
{
if(node==NULL)
return;//左,有趣);//数据);
顺序(节点->右,乐趣);
}
问题是你如何获得回报;没有归还任何东西。这有什么用? **注意,为了清晰起见,我对上面的代码进行了编辑。

这意味着当
x==1时,
从函数返回时,
foo(y)
不会执行

x!=1
,如果缩进代码并将括号放在
中,则会更清晰:

void foo(int x, int y) { 
   if(x == 1) {
      return;    //return from the function, don't proceed to foo(y)
   }
   foo(y);   
}
既没有表达式也没有大括号init列表的返回语句 只能在不返回值的函数中使用,即 返回类型为void的函数

请参见Ideone。

这意味着当
x==1
从函数返回时,
foo(y)
不会执行

x!=1
,如果缩进代码并将括号放在
中,则会更清晰:

void foo(int x, int y) { 
   if(x == 1) {
      return;    //return from the function, don't proceed to foo(y)
   }
   foo(y);   
}
既没有表达式也没有大括号init列表的返回语句 只能在不返回值的函数中使用,即 返回类型为void的函数


请参阅Ideone上的。

如果您将其格式设置得更好,则可能更容易查看:

void foo (int x, int y)
{ 
    if (x == 1)
        return;
    foo (y);
}

如果变量
x
等于
1
,它只返回。如果
x
不是等于
1
,那么代码会跳转到递归调用
foo
(我真的希望真正的代码不是这样,因为当它需要两个参数时,你用一个参数调用
foo

如果格式更好,可能更容易看到:

void foo (int x, int y)
{ 
    if (x == 1)
        return;
    foo (y);
}

如果变量
x
等于
1
,它只返回。如果
x
不是等于
1
,那么代码跳过对
foo
的递归调用(我真的希望真正的代码不是这样,因为当它需要两个参数时,你用一个参数调用
foo

尽管缩进很混乱,
返回值
在条件语句中

以下是编写代码的一种稍微不那么混乱的方法:

if (x == 1)
   return;
foo (y);

在条件语句中,
return
仅在
x==1
时执行。在所有情况下,都会调用
foo(y)

尽管缩进很混乱,但
返回值
在条件语句中

以下是编写代码的一种稍微不那么混乱的方法:

if (x == 1)
   return;
foo (y);

在条件语句中,
return
仅在
x==1
时执行。在所有情况下,都会调用
foo(y)

这意味着如果x==1,则函数返回而不执行foo(y)函数,如果x!=1,则执行foo(y)函数。

这意味着如果x==1,则函数返回而不执行foo(y)函数,如果x!=1,然后执行foo(y)函数。

foo
是一个函数

foo
接受两个参数。这两个参数都是
整数
。这些参数被命名为
x
y

函数体测试
x
变量中存储的值是否等于1。 如果存储在
x
中的值等于1,则函数将返回(退出)。 如果
x
中存储的值不等于1,则函数调用
foo(int x)

函数内部调用的
foo
可能与您提供代码的
foo
函数不同(因为它具有不同的接口/原型)


第二个
foo
的主体是什么(接受单个参数的主体)?
foo
的原型可能指定参数x&y的默认值(如果是这种情况,那么这可能是唯一的
foo
函数。

foo
是一个函数

foo
接受2个参数。这两个参数都是
integer
。这些参数被命名为
x
y

函数体测试
x
变量中存储的值是否等于1。 如果存储在
x
中的值等于1,则函数将返回(退出)。 如果
x
中存储的值不等于1,则函数调用
foo(int x)

函数内部调用的
foo
可能与您提供代码的
foo
函数不同(因为它具有不同的接口/原型)


第二个
foo
的主体是什么(采用单个参数的主体)?
foo
的原型可能会指定参数x&y的默认值(如果是这种情况,那么这可能是唯一的
foo
函数。

如果您习惯于在代码的最后看到
返回
,您可以将代码重写为:

void foo( int x, int y )
{
    if( x != 1 )
    {
        foo( y ) ;
    }
    else /* You can keep it to understand better visually. 
            Even if you don't keep it, the code would do the same */
    {
        return ; 
        /* returns the control to the caller code. 
           Make sure you understand that, it just returns the control but 
           without any value i.e., returning void. */
    }
}
编辑::
return
只将控件返回给调用者。如果您想返回带有某个值的控件,您可以
返回变量\u name
,如果您不想返回任何内容,只需
return

现实生活中的例子:
假设你被要求买一些肥皂来洗澡。现在,如果商店里有肥皂,你会回来把肥皂还给我,打电话的人会去洗澡。这是你带着一些价值回到打电话的人那里。但是假设,如果商店里没有肥皂了,那么你只要回到我身边,我就去洗澡了任何soap。这是指您返回到调用方,但没有值。在这两种情况下,您都会返回到调用方,因为调用方只在您返回时等待继续沐浴。

如果您习惯于在代码的最后看到
返回