[Error] return-statement with no value, in function returning 'int' [-fpermissive]
时间: 2024-02-12 15:07:17 浏览: 30
这个错误提示意味着你在一个返回 int 类型值的函数中使用了没有返回值的 return 语句。在 C/C++ 中,如果一个函数声明返回值为 int,那么在函数体中必须使用 return 语句返回一个 int 类型的值,否则编译器会报错。
请检查你的代码,确认在所有返回 int 类型值的函数中都使用了正确的 return 语句,并且返回值的类型和函数声明中的返回类型相匹配。如果你的函数确实不需要返回值,可以在函数声明中使用 void 来声明返回类型,例如:
```
void myFunction() {
// 函数体
}
```
如果你需要返回一个特殊值来表示函数执行成功或失败,可以使用枚举类型或者宏定义来定义返回值的常量,例如:
```
enum {
SUCCESS = 0,
ERROR = -1
};
int myFunction() {
if (/* 执行成功 */) {
return SUCCESS;
} else {
return ERROR;
}
}
```
相关问题
return-statement with no value,in function returning'int'
If a function returns an `int` but the `return` statement has no value, the function will return an undefined value. This can lead to unexpected behavior in your program.
For example, consider the following function:
```c
int foo() {
return;
}
```
This function has a return type of `int`, but the `return` statement has no value. When this function is called, it will return an undefined value. Depending on how the function is used in your program, this could lead to a segmentation fault or other errors.
To avoid this issue, always make sure that your `return` statements have a value that matches the return type of your function. For example:
```c
int bar() {
return 42;
}
```
This function has a return type of `int`, and the `return` statement returns the value `42`. When this function is called, it will return the value `42`.
error: return-statement with no value, in function returning ‘node*’ [-fpermissive] return;
这个错误是因为你的函数定义的返回类型是 `node*`,但是在函数中使用了一个没有返回值的 `return` 语句。这样会导致编译器无法确定函数的返回值,因此会产生这个错误。
如果你的函数确实没有返回值,那么应该将函数的返回类型改为 `void`。如果函数本来应该有返回值,那么你需要在函数中添加一个返回值,使得函数返回一个 `node*` 类型的值。
例如,如果你的函数应该返回一个指向 `node` 类型的指针,那么你可以在函数末尾添加一个 `return` 语句:
```
node* myFunction() {
// do some stuff
return some_node_pointer;
}
```
如果函数没有返回值,应该这样写:
```
void myFunction() {
// do some stuff
return; // 可以省略
}
```