<?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[Probleme mit Operatorüberladung]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe noch nicht soviel Ahnung von c++ und wolle üben Operatoren zu überladen. Dazu wollte ich mir eine Vector Klasse basteln.<br />
Aber schon bei der 1. Überladung von + gibts Probleme:</p>
<p>Die Main</p>
<pre><code class="language-cpp">#include &quot;Vector3D.h&quot;
#include &lt;Windows.h&gt;

int main () {
    Vector3D v = Vector3D(1,1,1);
	Vector3D z = Vector3D(2,3,4);

	Vector3D k = z+v;

	Sleep(20000);
	return 1;
}
</code></pre>
<p>Vector3D.cpp</p>
<pre><code class="language-cpp">#include &quot;Vector3D.h&quot;
#include &lt;Iostream&gt; 
#include &lt;math.h&gt;
void Vector3D::sagzahl() {std::cout &lt;&lt;&quot;x= &quot;&lt;&lt; x&lt;&lt;&quot; y= &quot;&lt;&lt;y&lt;&lt;&quot; z= &quot;&lt;&lt;z;}

void Vector3D::normalize() {float l = Vector3D::length();l=1/l;x*=l;y*=l;z*=l;}

float Vector3D::length() {return sqrt(x*x+y*y+z*z);}

float Vector3D::sqrt_length() {return (x*x+y*y+z*z);}

Vector3D Vector3D::normale(Vector3D v) {return Vector3D();}
</code></pre>
<p>Vector3D.h</p>
<pre><code class="language-cpp">#pragma once

class Vector3D
{
public:
	float x,y,z;
public:
	Vector3D(float x_,float y_,float z_): x(x_),y(y_),z(z_){};

	Vector3D():x(0),y(0),z(0) {};

	~Vector3D(void){}

	inline float get_x() {return x;}
	inline float get_y() {return y;}
	inline float get_z() {return z;}

	void normalize();

	float length();

	float sqrt_length();

    Vector3D normale(Vector3D);

	void sagzahl(); 

};
Vector3D operator + (const Vector3D&amp; a,const Vector3D&amp; b)	{return Vector3D(a.x + b.x, a.y + b.y, a.z + b.z);}
</code></pre>
<p>Es kommt als Fehler:</p>
<blockquote>
<p>Vector3D.obj : error LNK2005: &quot;class Vector3D __cdecl operator+(class Vector3D const &amp;,class Vector3D const &amp;)&quot; (??H@YA?AVVector3D@@ABV0@0@Z) already defined in Main.obj<br />
F:\Vector.exe : fatal error LNK1169: one or more multiply defined symbols found</p>
</blockquote>
<p>Was muß ich anders machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/180780/probleme-mit-operatorüberladung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 23:29:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/180780.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 May 2007 15:49:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit Operatorüberladung on Sun, 06 May 2007 15:49:31 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe noch nicht soviel Ahnung von c++ und wolle üben Operatoren zu überladen. Dazu wollte ich mir eine Vector Klasse basteln.<br />
Aber schon bei der 1. Überladung von + gibts Probleme:</p>
<p>Die Main</p>
<pre><code class="language-cpp">#include &quot;Vector3D.h&quot;
#include &lt;Windows.h&gt;

int main () {
    Vector3D v = Vector3D(1,1,1);
	Vector3D z = Vector3D(2,3,4);

	Vector3D k = z+v;

	Sleep(20000);
	return 1;
}
</code></pre>
<p>Vector3D.cpp</p>
<pre><code class="language-cpp">#include &quot;Vector3D.h&quot;
#include &lt;Iostream&gt; 
#include &lt;math.h&gt;
void Vector3D::sagzahl() {std::cout &lt;&lt;&quot;x= &quot;&lt;&lt; x&lt;&lt;&quot; y= &quot;&lt;&lt;y&lt;&lt;&quot; z= &quot;&lt;&lt;z;}

void Vector3D::normalize() {float l = Vector3D::length();l=1/l;x*=l;y*=l;z*=l;}

float Vector3D::length() {return sqrt(x*x+y*y+z*z);}

float Vector3D::sqrt_length() {return (x*x+y*y+z*z);}

Vector3D Vector3D::normale(Vector3D v) {return Vector3D();}
</code></pre>
<p>Vector3D.h</p>
<pre><code class="language-cpp">#pragma once

class Vector3D
{
public:
	float x,y,z;
public:
	Vector3D(float x_,float y_,float z_): x(x_),y(y_),z(z_){};

	Vector3D():x(0),y(0),z(0) {};

	~Vector3D(void){}

	inline float get_x() {return x;}
	inline float get_y() {return y;}
	inline float get_z() {return z;}

	void normalize();

	float length();

	float sqrt_length();

    Vector3D normale(Vector3D);

	void sagzahl(); 

};
Vector3D operator + (const Vector3D&amp; a,const Vector3D&amp; b)	{return Vector3D(a.x + b.x, a.y + b.y, a.z + b.z);}
</code></pre>
<p>Es kommt als Fehler:</p>
<blockquote>
<p>Vector3D.obj : error LNK2005: &quot;class Vector3D __cdecl operator+(class Vector3D const &amp;,class Vector3D const &amp;)&quot; (??H@YA?AVVector3D@@ABV0@0@Z) already defined in Main.obj<br />
F:\Vector.exe : fatal error LNK1169: one or more multiply defined symbols found</p>
</blockquote>
<p>Was muß ich anders machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1279736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1279736</guid><dc:creator><![CDATA[MisterX]]></dc:creator><pubDate>Sun, 06 May 2007 15:49:31 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Operatorüberladung on Sun, 06 May 2007 15:58:26 GMT]]></title><description><![CDATA[<p>Non-inline Funktionen sollten immer im Header nur deklariert und dann in der cpp definiert werden (nicht sicher ob es jetzt das Problem ist, aber ich könnts mir vorstellen)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1279741</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1279741</guid><dc:creator><![CDATA[Shinja]]></dc:creator><pubDate>Sun, 06 May 2007 15:58:26 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Operatorüberladung on Sun, 06 May 2007 16:00:39 GMT]]></title><description><![CDATA[<p>1. Deklaration des op+ nach Vector3D.h<br />
2. Implementation nach Vector3D.cpp (nicht wie jetzt in .h!)</p>
<p>d.h. ähnlich, wie du das mit normalize() und length()<br />
auch gemacht hast.</p>
<p>Vector3D.cpp und Main.cpp lesen beide Vector3D.h, daher der Fehler</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1279743</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1279743</guid><dc:creator><![CDATA[helpie]]></dc:creator><pubDate>Sun, 06 May 2007 16:00:39 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Operatorüberladung on Sun, 06 May 2007 16:06:00 GMT]]></title><description><![CDATA[<p>helpie schrieb:</p>
<blockquote>
<p>1. Deklaration des op+ nach Vector3D.h<br />
2. Implementation nach Vector3D.cpp (nicht wie jetzt in .h!)</p>
<p>d.h. ähnlich, wie du das mit normalize() und length()<br />
auch gemacht hast.</p>
<p>Vector3D.cpp und Main.cpp lesen beide Vector3D.h, daher der Fehler</p>
</blockquote>
<p>Danke, klappt jetzt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1279746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1279746</guid><dc:creator><![CDATA[MisterX]]></dc:creator><pubDate>Sun, 06 May 2007 16:06:00 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Operatorüberladung on Mon, 07 May 2007 08:51:42 GMT]]></title><description><![CDATA[<p>oder die Funktion (bzw. den Operator) als inline deklarieren...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280116</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280116</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Mon, 07 May 2007 08:51:42 GMT</pubDate></item></channel></rss>