类矩阵问题 [英] Classes Matrix question
问题描述
大家好。我正在编写一个使用名为matrix的类的程序。我编写了所有不同的函数,构造函数等。
当我运行程序时,我收到构造函数,我将其置于构造函数中,然后程序崩溃。我不知道我的问题在哪里。
矩阵的大小为2x2到10x10,它必须是正方形。
下面是代码:
Hello everyone. I''m writing a program which uses a class called matrix. I have written all of the different functions, constructor, etc.
When I run the program I receive "Constructor", which I placed in the constructor, and then the program crashes. I have no clue where my problem is.
The matrix is for size 2x2 up to 10x10, and it must be square.
Below is the code:
推荐答案
你的循环都有一个错误。当数组的最大尺寸
等于10时,有效索引值为0,1,2,3,4,5,6,7,8和9(计算它们:
有10个不同的索引值)。因此你的循环应该都有一个
终止条件,例如:
Your loops all have an off by one error. When the maximum dimension of an array
equals 10, valid index values are 0, 1, 2, 3, 4, 5, 6 , 7, 8, and 9 (count them:
there are 10 different index values). Therefore your loops should all have a
terminating condition such as:
再次回到我的救援行动中,何塞哈?
我明白你在说什么,这是对的......我没想到我什么时候把它们做得比等于10.程序仍然崩溃,所以函数不会超出范围(或者不管它的名称)。
J
Back to my rescue again hun JosAH?
I understand what you''re saying, and that is right...I wasn''t thinking when I made them less than or equal to 10. The program still crashes, so the functions aren''t going out of scope (or whatever it''s called).
J
>
再次回到我的救援胡约什啊?
我明白你在说什么,这是对的...当我让它们小于或等于10时我没在想。仍然崩溃,所以功能不会超出范围(或任何它的名称)。
J
Back to my rescue again hun JosAH?
I understand what you''re saying, and that is right...I wasn''t thinking when I made them less than or equal to 10. The program still crashes, so the functions aren''t going out of scope (or whatever it''s called).
J
我仔细看了你的代码:看看你的ctor中的内循环:
它增加''我'而不是''j''它会射击你为此而努力;-)
亲切的问候,
Jos
I took a bit closer look at your code: have a look at the inner loop in your ctor:
it increments ''i'' instead of ''j'' and it will shoot you in your foot for it ;-)
kind regards,
Jos
这篇关于类矩阵问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!