我一直在努力解决这个错误。我该怎么解决呢?我试过把函数放在主函数之外,但它仍然不起作用。
int mutexlock = 1, full = 0, emp = 20, x = 0, buffer[100];
void producer();
void consumer();
int randomgenerator();
int main() {
void producer() {
int d = randomgenerator();
buffer[x] = d;
cout << "\n" << d;
x++;
}
void consumer() {
x--;
cout << "\n" << buffer[x] << endl
cout << "sum" << buffer[x] << (buffer[x] + buffer[x]);
}
int randomgenerator() {
int num = rand() % 6 + 1;
return (num);
}
}
错误:
error: a function-definition is not allowed here before ‘{’ token
{
发布于 2022-04-23 11:31:33
你应该把所有的功能都排除在主功能之外。此外,请将程序启动后要运行的代码放在主函数中。
示例:
int main() {
producer();
consumer();
}
https://stackoverflow.com/questions/71979212
复制相似问题