代码外部函数 [英] Code outside functions
本文介绍了代码外部函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在所有函数之外编写了这个代码:
I have written this code outside all functions:
int l, k;
for (l = 1; l <= node; l++)
{
for (k = 1; k <= node; k++)
{
flow[i][j] = capacity[i][j];
flow[j][i] = 0;
}
}
编译时出现以下错误: / p>
It is giving me the following error on compilation:
shalini@shalini-desktop:~$ g++ -o output fords.cpp
fords.cpp:63: error: expected unqualified-id before ‘for’
fords.cpp:63: error: expected constructor, destructor, or type conversion before ‘<=’ token
fords.cpp:63: error: expected constructor, destructor, or type conversion before ‘++’ tok
推荐答案
你不能在函数之外编写代码。你可以在函数之外的唯一的事情是声明,如全局变量声明(通常是一个坏主意),函数声明等。尝试把它放在一个函数 int main(){}
You can't write code outside of functions. The only things you can have outside of functions are declarations such as global variable declarations (usually a bad idea), function declarations etc. Try putting it in a function like int main(){}
这篇关于代码外部函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文