我想根据main()中的输入定义全局数组(在其他函数中使用)。(具体是数组大小)。 extern关键字没有帮助。在main()中定义全局变量
#include <iostream>
using namespace std;
void gen_sieve_primes(void);
int main() {
int MaxNum;
cin >> MaxNum;
int *primes = new int[MaxNum];
delete[] primes;
return 0;
}
//functions where variable MaxNum is used
1)不要使用全局变量。 2)不要使用数组;而不是像'std :: vector'那样使用容器。 –
你确定你想要一个数组而不是'std :: vector'吗? –