在巨大的解决方案中向类中添加成员时出现堆栈溢出错误

发布于 2024-11-30 03:33:34 字数 279 浏览 6 评论 0原文

请看一下这段代码:

class A
{
int a;
};

然后再向 A 类添加一个成员:

class A
{
int a;
int b;
};

在我的庞大解决方案中,当我向一个类中再添加一个成员(如 A 类中的成员 b)时,我会收到堆栈溢出错误。我认为这在某种程度上与写入未保留的数据地址有关。

Visual Studio中有没有办法找到这样的地方?为什么会发生这种错误,有更好的想法吗?

Please look at this code:

class A
{
int a;
};

Then add one more member to class A:

class A
{
int a;
int b;
};

In my huge solution when I add one more member to a class (like member b in class A) I get stack overflow error. I assume that this is somehow related to writing to not reserved data adresses.

Is there any way to find such places in visual studio? Any better ideas why such kind of error happens?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹泡泡o 2024-12-07 03:33:34

好吧,第一个问题:你真的添加了一个 int 吗?如果是,那么这个答案适用。

在以下情况下可能会发生这种情况:

  • 您的类太大,其构造函数将导致堆栈溢出,因为它无法在堆栈上分配足够的内存来为所有成员分配内存。
  • 您正在某处进行指针算术,当您添加成员时,该算术会失败。
  • 您正在该对象的堆栈上创建一个巨大的数组,当您添加此成员时,该数组会变得太大。

我建议您首先向我们提供一些更相关的信息(平台、编译器、真实代码/类定义)。

Well, first question: Are you really adding an int? If yes, then this answer is applicable.

This can happen when:

  • Your class is so enormous that it's constructor will cause a stack overflow because it can not allocate enough memory on the stack to allocate memory for all members.
  • You are doing pointer arithmic somewhere that fails when you add a member.
  • You are creating an huge array on the stack of this object that becomes too large when you add this member.

I would suggest you supply us with some more relevant information (platform, compiler, real code/class definition) first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文