......(代码)...... void byval(struct Array a) { //什么都不做 } 提前致谢! 解决方案 Dave< dr ******* @ yahoo.com>在留言中写道 新闻:1c ************************** @ posting.google.c om ... 我目前正在开展一个小型项目(很赞赏我的CS课程)比较传递值和传递之间的时差。我正在传递一个50000 int'的数组。但是,由于在C ++中默认情况下通过引用传递数组,我需要将数组嵌入到结构中,以便按值传递它。问题是,这样做时会出现分段错误。我正在使用Dev-c ++ 编译器。任何想法? 堆栈溢出可能。你真的需要做这样的测试吗?我们已经知道通过值传递将复制参数,这意味着复制 50,000英镑,并且通过引用传递不会。你不需要把它运行到 知道会有很大的不同。 DW David White < [email protected]>在消息中写道 新闻:A8 *************** @ nasal.pacific.net.au ... Dave<组成; dr ******* @ yahoo.com>在消息中写道新闻:1c ************************** @ posting.google.c om ... 我目前正在开展一个小型项目(很赞赏我的CS课程)比较传递值和传递之间的时差。我正在传递一个50000 int'的数组。但是,由于在C ++中默认情况下通过引用传递数组,我需要将数组嵌入到结构中,以便按值传递它。问题是,这样做时会出现分段错误。我正在使用Dev-c ++ 编译器。任何想法? 堆栈溢出可能。你真的需要做这样的测试吗?我们已经知道通过值传递将复制参数,这意味着复制5万英寸,并且通过引用传递不会。你不需要运行它来知道会有很大的不同。 考虑到他正在为一堂课做这件事,并试图为自己学习, 是的 - 他确实。 " jeffc" <无**** @ nowhere.com>在消息新闻中写道:< 3f ******** @ news1.prserv.net> ... " David White" < [email protected]>在消息中写道新闻:A8 *************** @ nasal.pacific.net.au ... Dave< dr ** *****@yahoo.com>在消息中写道新闻:1c ************************** @ posting.google.c om ... 我目前正在开展一个小型项目(很赞赏我的CS课程)比较传递值和传递之间的时差。我正在传递一个50000 int'的数组。但是,由于在C ++中默认情况下通过引用传递数组,我需要将数组嵌入到结构中,以便按值传递它。问题是,这样做时会出现分段错误。我正在使用Dev-c ++ 编译器。任何想法? 堆栈溢出可能。你真的需要做这样的测试吗?我们已经知道通过值传递将复制参数,这意味着复制5万英寸,并且通过引用传递不会。你不需要运行它来知道会有很大的不同。 考虑到他正在上课,并试图学习对于他自己,是的 - 他确实。 确切地说 - 因为这个原因我做了。我已经知道有一个很大的 差异。事实上,我必须在学校的一台计算机上迭代传递参考 函数大约400000次 让它在任何时候都可以注册。我有这个问题,因为 相同的代码适用于VisualStudio.net编译器,但不适用于 Dev-C ++。我想我可以和Borland一起尝试。 因为.net框架,我不想使用VisualStudio.net。 除非你能告诉我如何在一个 VisualStudio.net编译中排除框架(是托管的c ++?) - 这也可以工作 。 Dave I''m currently working on a small project (admitedly for my CS class)that compares the time difference between passing by value and passingby reference. I''m passing an array of 50000 int''s. However, since inC++ an array is passed by reference by default I need to embed thearray into a struct in order to pass it by value. The problem is thatI get a segmentation error when doing so. I''m using the Dev-c++compiler. Any ideas?Here''s the basic source:....(code)...void byval(struct Array a);struct Array{int data[50000];};....(code)...byval(a);....(code)...void byval(struct Array a){// do nothing}Thanks in advance! 解决方案 Dave <dr*******@yahoo.com> wrote in messagenews:1c**************************@posting.google.c om... I''m currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I''m passing an array of 50000 int''s. However, since in C++ an array is passed by reference by default I need to embed the array into a struct in order to pass it by value. The problem is that I get a segmentation error when doing so. I''m using the Dev-c++ compiler. Any ideas?A stack overflow maybe. Do you really need to do such a test? We alreadyknow that passing by value will copy the argument, which means copying50,000 ints, and passing by reference won''t. You don''t need to run it toknow there will be a huge difference.DW"David White" <[email protected]> wrote in messagenews:A8***************@nasal.pacific.net.au... Dave <dr*******@yahoo.com> wrote in message news:1c**************************@posting.google.c om... I''m currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I''m passing an array of 50000 int''s. However, since in C++ an array is passed by reference by default I need to embed the array into a struct in order to pass it by value. The problem is that I get a segmentation error when doing so. I''m using the Dev-c++ compiler. Any ideas? A stack overflow maybe. Do you really need to do such a test? We already know that passing by value will copy the argument, which means copying 50,000 ints, and passing by reference won''t. You don''t need to run it to know there will be a huge difference.Considering that he''s doing it for a class, and trying to learn for himself,yes - he does."jeffc" <no****@nowhere.com> wrote in message news:<3f********@news1.prserv.net>... "David White" <[email protected]> wrote in message news:A8***************@nasal.pacific.net.au... Dave <dr*******@yahoo.com> wrote in message news:1c**************************@posting.google.c om... I''m currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I''m passing an array of 50000 int''s. However, since in C++ an array is passed by reference by default I need to embed the array into a struct in order to pass it by value. The problem is that I get a segmentation error when doing so. I''m using the Dev-c++ compiler. Any ideas? A stack overflow maybe. Do you really need to do such a test? We already know that passing by value will copy the argument, which means copying 50,000 ints, and passing by reference won''t. You don''t need to run it to know there will be a huge difference. Considering that he''s doing it for a class, and trying to learn for himself, yes - he does.Exactly - for that reason I do. I already know that there''s a bigdifference. In fact, I have to iterate the passing by referencefunction about 400000 times on one of the school''s computer just toget it to register any time at all. I have the question because thesame code works with the VisualStudio.net compiler, but not withDev-C++. I suppose I could try it with Borland.I don''t want to use VisualStudio.net because of the .net framework.Unless you can tell me how to exclude the framework in aVisualStudio.net compilation (is that managed c++?) - that would worktoo.Dave 这篇关于按值传递结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 16:48