<?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[python&amp;gt;&amp;gt;c++]]></title><description><![CDATA[<p>hey<br />
i have such a code on python that i would like to translate to c++ i dont know much about neither of them can anyone help with questions like:<br />
how to define a function that have a class as return ?<br />
and what is the meaning of this self and how can we get the same meaning on a c++ code ?</p>
<p>class quaternion:<br />
def __init__(self, a, b, c, d):<br />
self.R = float(a) # real part<br />
self.I = float(b) # first imaginary part<br />
self.J = float(c) # second imaginary part<br />
self.K = float(d) # third imaginary part<br />
def normalize(self):<br />
n = self.norm()<br />
qret = quaternion(self.R, self.I, self.J, self.K)<br />
if n == 0:<br />
print 'cant normalize, is 0'<br />
else:<br />
qret.R = self.R/n # real part<br />
qret.I = self.I/n # first imaginary part<br />
qret.J = self.J/n # second imaginary part<br />
qret.K = self.K/n # third imaginary part<br />
return qret<br />
return quaternion(a, b, c, d)</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/331467/python-gt-gt-c</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 15:51:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/331467.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Mar 2015 14:04:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 14:04:53 GMT]]></title><description><![CDATA[<p>hey<br />
i have such a code on python that i would like to translate to c++ i dont know much about neither of them can anyone help with questions like:<br />
how to define a function that have a class as return ?<br />
and what is the meaning of this self and how can we get the same meaning on a c++ code ?</p>
<p>class quaternion:<br />
def __init__(self, a, b, c, d):<br />
self.R = float(a) # real part<br />
self.I = float(b) # first imaginary part<br />
self.J = float(c) # second imaginary part<br />
self.K = float(d) # third imaginary part<br />
def normalize(self):<br />
n = self.norm()<br />
qret = quaternion(self.R, self.I, self.J, self.K)<br />
if n == 0:<br />
print 'cant normalize, is 0'<br />
else:<br />
qret.R = self.R/n # real part<br />
qret.I = self.I/n # first imaginary part<br />
qret.J = self.J/n # second imaginary part<br />
qret.K = self.K/n # third imaginary part<br />
return qret<br />
return quaternion(a, b, c, d)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444912</guid><dc:creator><![CDATA[abbl1]]></dc:creator><pubDate>Mon, 02 Mar 2015 14:04:53 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 14:32:01 GMT]]></title><description><![CDATA[<p>abbl1 schrieb:</p>
<blockquote>
<p>how to define a function that have a class as return ?</p>
</blockquote>
<p>Use the class name as return type.</p>
<p>abbl1 schrieb:</p>
<blockquote>
<p>and what is the meaning of this self and how can we get the same meaning on a c++ code ?</p>
</blockquote>
<p>By convention, self is the usual name for the first method parameter, which is a reference to the instance used for the method call. It is used to access the class instance's data attributes. In C++, you don't need it.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444915</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444915</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Mon, 02 Mar 2015 14:32:01 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 14:39:21 GMT]]></title><description><![CDATA[<p>so is that right if i write this for this python code?</p>
<p>class quaternion {</p>
<p>float R,I,J,K;</p>
<p>public:</p>
<p>quaternion (float,float,float,float);</p>
<p>quaternion normalize() {</p>
<p>n=norm();<br />
qret=quaternion(R,I,J,K);<br />
qret.R=R/n;<br />
qret.I=I/n;<br />
qret.J=J/n;<br />
qret.K=K/n;<br />
return qret;<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444916</guid><dc:creator><![CDATA[abbl1]]></dc:creator><pubDate>Mon, 02 Mar 2015 14:39:21 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 14:41:14 GMT]]></title><description><![CDATA[<p>MFK schrieb:</p>
<blockquote>
<p>By convention, self is the usual name for the first method parameter, which is a reference to the instance used for the method call. It is used to access the class instance's data attributes. In C++, you don't need it.</p>
</blockquote>
<p>The equivalent in C++ is named &quot;this&quot;.<br />
--&gt; <a href="http://www.tutorialspoint.com/cplusplus/cpp_this_pointer.htm" rel="nofollow">http://www.tutorialspoint.com/cplusplus/cpp_this_pointer.htm</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444917</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 02 Mar 2015 14:41:14 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 14:48:39 GMT]]></title><description><![CDATA[<p>abbl1 schrieb:</p>
<blockquote>
<p>so is that right if i write this for this python code?</p>
</blockquote>
<p>- Definition of qret is missing<br />
- quaternion constructor definition is missing<br />
- You're not checking for n==0</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444918</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444918</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Mon, 02 Mar 2015 14:48:39 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 14:58:15 GMT]]></title><description><![CDATA[<p>thanks guys <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
just one last check :<br />
class quaternion {</p>
<p>float R,I,J,K;<br />
public:</p>
<p>quaternion (float a ,float b ,float c ,float d ) {</p>
<p>R=a; I=b; J=c; K=d; }<br />
quaternion normalize() {</p>
<p>quaternion qret;<br />
float n;</p>
<p>n=norm();<br />
qret=quaternion(R,I,J,K);<br />
qret.R=R/n;<br />
qret.I=I/n;<br />
qret.J=J/n;<br />
qret.K=K/n;<br />
return qret;<br />
}<br />
} return quaternion(a, b, c, d);<br />
(forget about the n==0 )</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444920</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444920</guid><dc:creator><![CDATA[abbl1]]></dc:creator><pubDate>Mon, 02 Mar 2015 14:58:15 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 15:38:09 GMT]]></title><description><![CDATA[<p>There are still some problems, but how to fix them depends on what you want:</p>
<p>Do you want to be as close to the Python code as possible, or do you want good C++?<br />
Do you want code that works? Because right now your C++ code won't work, just like the Python code.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444925</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Mon, 02 Mar 2015 15:38:09 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 15:55:41 GMT]]></title><description><![CDATA[<p>so how would be the perfect code for it?<br />
i dont know much about it so i based my work on the python code<br />
PLEASE HELP <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444926</guid><dc:creator><![CDATA[abbl1]]></dc:creator><pubDate>Mon, 02 Mar 2015 15:55:41 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 17:44:29 GMT]]></title><description><![CDATA[<p>@abbl1<br />
The perfect code for what?<br />
And say we give you &quot;the perfect code&quot;. What would you do with it? You're obviously not an able programmer, so what would be the point of you having it? I mean, you wouldn't be able to use it anyway.</p>
<p>And after considering this, it's beginning to smell distinctively like homework.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444945</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444945</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 02 Mar 2015 17:44:29 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 18:32:23 GMT]]></title><description><![CDATA[<p>@ hustbaer<br />
you're right i'm not a programmer i'm an electrical engineer and i'm doing an internship whithin the first step i have to do is to translate a very very long python code to c++ so i can do something with it in reality and unfortantly as you said i'm not a programmer ,i'm reading books, i'm trying to do something good with this programme i'm trying hard but as every aknowlege person who want to do something good, i'm asking for help i though with this forum maybe i can find something, unfortuntly there is people like u who smell homework everywhere so if u want help, please don't, but at least let people who want to do something TRY.<br />
(and i've chosen this part of the programme because it resumes all the problemes that i have with classes and functions )</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444960</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444960</guid><dc:creator><![CDATA[abbl1]]></dc:creator><pubDate>Mon, 02 Mar 2015 18:32:23 GMT</pubDate></item><item><title><![CDATA[Reply to python&amp;gt;&amp;gt;c++ on Mon, 02 Mar 2015 19:07:03 GMT]]></title><description><![CDATA[<p>@abbl1<br />
I understand that this might be frustrating for you. However I do also think that it's my right to make an observation.</p>
<p>Let me make another observation: the code you posted with the question if it's OK, doesn't even compile. What do you want to do with a piece of code, if you cannot even compile it?<br />
And then the phrase &quot;just one last check&quot;. One last check before ... what?</p>
<p>So you tell me: If this doesn't smell like homework, then what does?</p>
<p>I will however not interfere if anyone wants to help you - aside from making my &quot;observations&quot; that is.</p>
<p>----</p>
<p>That aside...<br />
Maybe you should start with settings up a development environment where you can compile and run C++ code.<br />
The chances of learning C++, even just &quot;a little bit&quot;, without a working development environment, are close to zero.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444966</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 02 Mar 2015 19:07:03 GMT</pubDate></item></channel></rss>