本文介绍了二维数组模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我认为operator []()成员函数无法正常工作,是吗?
其他人都知道如何制作模板来制作二维数组来自

std :: vectors ???我想使用普通的数组[ROW] [COL]语法。

http://groups.google.com/group/comp....092f0f6c9bf13a

I think that the operator[]() member function does not work correctly, does
anyone else know how to make a template for making two dimensional arrays from
std::vectors ??? I want to use normal Array[ROW][COL] Syntax.

推荐答案



在发布的代码中(您可以包括):


w_elem_type * operator [](t_Size i_index)

{

return& (m_data [i_index * m_rows]);

}


''i_index * m_rows'' - 对我来说似乎有点可疑。现在已经很晚了

我不会花太多时间考虑它,但我认为

''i_index / m_rows''会更正确,但我可能错了。在纸上画一个

3x3矩阵并进行数学计算。


-

Erik Wikstr?m

In the code posted (which you could have included):

w_elem_type * operator[]( t_Size i_index )
{
return & ( m_data[ i_index * m_rows ] );
}

The ''i_index * m_rows''-part seems kind of fishy to me. It''s quite late
right now and I wont spend time thinking much about it, but I think that
''i_index / m_rows'' would be more correct, but I might be wrong. Draw a
3x3 matrix on paper and do the math.

--
Erik Wikstr?m




在发布的代码中(您可以包括):


w_elem_type * operator [](t_Size i_index)

{

return& (m_data [i_index * m_rows]);

}


''i_index * m_rows'' - 对我来说似乎有点可疑。现在已经很晚了

我不会花太多时间考虑它,但我认为''i_index /

m_rows''会更正确,但我可能错了。在

纸上画一个3x3矩阵并做数学运算。


-

Erik Wikstr?m


In the code posted (which you could have included):

w_elem_type * operator[]( t_Size i_index )
{
return & ( m_data[ i_index * m_rows ] );
}

The ''i_index * m_rows''-part seems kind of fishy to me. It''s quite late right
now and I wont spend time thinking much about it, but I think that ''i_index /
m_rows'' would be more correct, but I might be wrong. Draw a 3x3 matrix on
paper and do the math.

--
Erik Wikstr?m



我已将所有内容部分转换为Array [ROW] [COL]顺序。我发现

我需要将上述功能转换为


return& (m_data [i_index * m_columns]);


我在发布此

消息后一分钟内发现了我的问题的解决方案。我链接的代码可能仍然正确。


感谢您的帮助。

I had partially converted everything over to Array[ROW][COL] order. I discovered
that I needed to convert the above function to

return & ( m_data[ i_index * m_columns ] );

I discovered this solution to my problem within a minute after I posted this
message. The code that I had linked to may still be correct.

Thanks for your help.





为什么?

Why?


这篇关于二维数组模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 00:27