gpt4 book ai didi

c++ - C++程序中的堆栈溢出错误

转载 作者:太空狗 更新时间:2023-10-29 20:04:23 25 4
gpt4 key购买 nike

所以我有这个复杂的类,我想要一个复数的二维数组这是代码的一部分而不是全部代码

class Complex {
public:
/* construction/destruction */
Complex(double r, double i) { this->r = r; this->i = i; }
Complex() { r=0.0; i=0.0; }
~Complex() { r=0.0; i=0.0; }
/* operations */
Complex operator+(Complex &c) { return Complex( r+c.r, i+c.i ); }
double r, i;
};

int main()
{
const int HEIGHT = 256;
const int WIDTH = 256;
Complex G[HEIGHT][WIDTH];
}

所以行 Complex G[HEIGHT][WIDTH];是导致问题的线路,知道为什么吗?

最佳答案

Visual Studio 默认为 1MB 堆栈大小,它看起来像:

Complex G[HEIGHT][WIDTH];

将只有大约 1MB,您可以使用 /F 修改它文件说(强调我的):

Without this option the stack size defaults to 1 MB. The number argument can be in decimal or C-language notation. The argument can range from 1 to the maximum stack size accepted by the linker. The linker rounds up the specified value to the nearest 4 bytes. The space between /F and numberis optional.

最明显的替代方法是通过newstd::vector 使用动态内存分配。 .

Visual Studio 据我所知实际上有 one of the smaller default堆栈大小:

platform    default size       
=====================================
SunOS/Solaris 8192K bytes
Linux 8192K bytes
Windows 1024K bytes
cygwin 2048K bytes
Mac OS X 8192K bytes

关于c++ - C++程序中的堆栈溢出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20234048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com