<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[how to return a matrix?]]></title><description><![CDATA[<p>hey <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
i try to return a matrix from a function I have tried many ways unfortunately it doesn’t work there is my code:<br />
float** toMatrix() {<br />
float mat[3][3]; float a ; float b ; float c ; float d ;</p>
<p>a=R; b=I; c=J; d=K;</p>
<p>mat[0][0]= a*a+b*b-c*c-d*d; mat[0][1]= 2*(b*c-a*d); mat[0][2]= 2*(a*c+b*d);</p>
<p>mat[1][0]= 2*(b*c+a*d); mat[1][1]= a*a-b*b+c*c-d*d; mat[1][2]=2*(c*d-a*b);</p>
<p>mat[2][0]= 2*(b*d-a*c); mat[2][1]=2*(a*b+c*d); mat[2][2]=a*a-b*b-c*c+d*d;</p>
<p>return mat;</p>
<p>}</p>
<p>and i have this when i try to compile &quot; error: cannot convert 'float (*)[3]' to 'float**' in return<br />
return mat;&quot;<br />
have anyone an idea of how can i do this?<br />
thanks<br />
^</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/331513/how-to-return-a-matrix</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 14:55:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/331513.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 04 Mar 2015 14:16:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to how to return a matrix? on Wed, 04 Mar 2015 14:16:51 GMT]]></title><description><![CDATA[<p>hey <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
i try to return a matrix from a function I have tried many ways unfortunately it doesn’t work there is my code:<br />
float** toMatrix() {<br />
float mat[3][3]; float a ; float b ; float c ; float d ;</p>
<p>a=R; b=I; c=J; d=K;</p>
<p>mat[0][0]= a*a+b*b-c*c-d*d; mat[0][1]= 2*(b*c-a*d); mat[0][2]= 2*(a*c+b*d);</p>
<p>mat[1][0]= 2*(b*c+a*d); mat[1][1]= a*a-b*b+c*c-d*d; mat[1][2]=2*(c*d-a*b);</p>
<p>mat[2][0]= 2*(b*d-a*c); mat[2][1]=2*(a*b+c*d); mat[2][2]=a*a-b*b-c*c+d*d;</p>
<p>return mat;</p>
<p>}</p>
<p>and i have this when i try to compile &quot; error: cannot convert 'float (*)[3]' to 'float**' in return<br />
return mat;&quot;<br />
have anyone an idea of how can i do this?<br />
thanks<br />
^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2445236</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2445236</guid><dc:creator><![CDATA[abbl1]]></dc:creator><pubDate>Wed, 04 Mar 2015 14:16:51 GMT</pubDate></item><item><title><![CDATA[Reply to how to return a matrix? on Wed, 04 Mar 2015 15:41:49 GMT]]></title><description><![CDATA[<pre><code>std::array&lt;std::array&lt;float, 3&gt;, 3&gt; mat;
</code></pre>
<p>Also use this type as the return type. Or you could write a matrix class and use that.</p>
<p>Even if your code would work like you inteded to, it would be undefined behaviour.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2445246</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2445246</guid><dc:creator><![CDATA[patrick246]]></dc:creator><pubDate>Wed, 04 Mar 2015 15:41:49 GMT</pubDate></item><item><title><![CDATA[Reply to how to return a matrix? on Wed, 04 Mar 2015 19:19:13 GMT]]></title><description><![CDATA[<p>In general: A pointer is not an array and an array is not a pointer.</p>
<p>Corollary: A pointer to a pointer is not a pointer to an array and neither of those is a 2D-array, and vice versa.</p>
<p>This is not just a syntactic difference. The actual data layout in memory is totally different.</p>
<p>But, as patrick246 explained, it is unusual to work with raw pointers and arrays in C++ anyway.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2445283</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2445283</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 04 Mar 2015 19:19:13 GMT</pubDate></item></channel></rss>