我有下面列出的代码,并在运行时报告堆栈溢出.我使用pass by value来showTest().我期望它会将Test结构的副本复制到堆栈(推送到堆栈),然后在函数调用结束时Test释放结构(弹出堆栈).所以我打三次电话.它应该推入堆栈并在每个函数调用结束时弹出.
如果每次调用函数时它都会按下并弹出堆栈,我看不到任何堆栈问题.但是,当我运行此代码时,它会在第一行报告堆栈溢出异常main.(我使用Visual Studio 2017.)
如果我删除其中一个showTest()函数调用,那么我可以让它工作.
任何反馈都将受到高度赞赏.
#include <iostream>
struct Test
{
static int Userid;
int data[100000] = { };
Test()
{
++Userid;
};
};
int Test::Userid = 0;
void showTest(Test i_myint)
{
std::cout << "test" << std::endl;
}
int main()
{
Test *pint = new Test();
showTest(*pint);
Test *pint2 = new Test();
showTest(*pint2);
Test *pint3 = new Test();
showTest(*pint3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)