读书人

新手一个有关问题求解。

发布时间: 2013-07-27 22:21:01 作者: rapoo

新手一个问题求解。。

                                                                            
[解决办法]
栈空间是有限的, 放那么大的对象, 溢出了撒.
[解决办法]
栈溢出了,把a放到外面:

#include<cstdio>
#include<iostream>
using namespace std;

const int maxn = 10000010;


class P{

public:

int a[maxn];
bool b[maxn];
int c[maxn];
int d[maxn];
};

P a;

int main()
{

//P a;
cout<<0<<endl;

return 0;
}


引用:



#include<cstdio>
#include<iostream>
using namespace std;

const int maxn = 10000010;


class P{

public:

int a[maxn];
bool b[maxn];
int c[maxn];
int d[maxn];
};

//P a;

int main()
{

P a;
cout<<0<<endl;

return 0;
}






上面一段代码,困扰了我半天。。
在mac下面运行就会segmentation fault,


而把 cout<<0<<endl; 注释掉就没问题。
然后P a的定义放在main外面也不会有问题。

最后,上面这些问题到了windows下就都没问题了。
求解新手一个有关问题求解。

读书人网 >C++

热点推荐