<?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[fehler: methode [with T = int] cannot be overloaded]]></title><description><![CDATA[<p>hmm ja also ich bin grad dabei ein paar templateklassen zu schreiben. bis jetzt hat auch alles funktioniert. leider sagt er mir jetzt &quot;methode [with T = int] cannot be overloaded&quot;</p>
<pre><code class="language-cpp">//entity.h
#ifndef _ENTITY_H
#define _ENTITY_H

#include &quot;vector.h&quot;

namespace VR
{

	template &lt;class T&gt;
	class Entity
	{
		public:
			Entity(T intiX, T initY, T initXSpeed, T initYSpeed);
			Entity(Vector&lt;T&gt; initPosition, Vector&lt;T&gt; initSpeed);
			~Entity();

			void accelerate(Vector&lt;T&gt; acc);
			void step();

			const Vector&lt;T&gt; getPosition();
			const Vector&lt;T&gt; getSpeed();

		private:
			Entity();
			void accelerate(Vector&lt;T&gt; acc);
			void step();

			Vector&lt;T&gt; position, speed;
	};

	template &lt;class T&gt;
	Entity&lt;T&gt;::Entity()
	{
	}

	template &lt;class T&gt;
	Entity&lt;T&gt;::Entity(T initX, T initY, T initXSpeed, T initYSpeed)
	:position(Vector&lt;T&gt;(initX, initY)), speed(Vector&lt;T&gt;(initXSpeed, initYSpeed))
	{
	}

	template &lt;class T&gt;
	Entity&lt;T&gt;::Entity(Vector&lt;T&gt; initPosition, Vector&lt;T&gt; initSpeed)
	:position(initPosition), speed(initSpeed)
	{
	}

	template &lt;class T&gt;
	Entity&lt;T&gt;::~Entity()
	{
	}

	template &lt;class T&gt;
	void Entity&lt;T&gt;::accelerate(Vector&lt;T&gt; acc) //hier meckert er (fehler genauer weiter unten)
	{
		speed += acc;
	}

	template &lt;class T&gt;
	void Entity&lt;T&gt;::step() //und hier meckert er (fehler genauer weiter unten)
	{
		position += speed;
	}

	template &lt;class T&gt;
	const Vector&lt;T&gt; Entity&lt;T&gt;::getPosition()
	{
		return position;
	}

	template &lt;class T&gt;
	const Vector&lt;T&gt; Entity&lt;T&gt;::getSpeed()
	{
		return speed;
	}
}
</code></pre>
<pre><code class="language-cpp">//vector.h
#ifndef _VECTOR_H
#define _VECTOR_H

#include &quot;coordinate.h&quot;

namespace VR
{

	template &lt;class T&gt;
	class Vector : public Coordinate&lt;T&gt;
	{
		public:
			Vector();
			Vector(T initX, T initY);
			~Vector();

			void operator+=(Coordinate&lt;T&gt; aCoordinate);

			void addX(T aX);
			void addY(T aY);
			void add(T aX, T aY);
	};

	template &lt;class T&gt;
	Vector&lt;T&gt; ::Vector()
	{
	}

	template &lt;class T&gt;
	Vector&lt;T&gt;::Vector(T initX, T initY)
	{
		Coordinate&lt;T&gt;::x = initX;
		Coordinate&lt;T&gt;::y = initY;
	}

	template &lt;class T&gt;
	Vector&lt;T&gt;::~Vector()
	{
	}

	template &lt;class T&gt;
	void Vector&lt;T&gt;::operator+=(Coordinate&lt;T&gt; aCoordinate)
	{
		Coordinate&lt;T&gt;::x += aCoordinate[0];
		Coordinate&lt;T&gt;::y += aCoordinate[1];
	}

	template &lt;class T&gt;
	void Vector&lt;T&gt;::addX(T aX)
	{
		setX(Coordinate&lt;T&gt;::getX() + aX);
	}

	template &lt;class T&gt;
	void Vector&lt;T&gt;::addY(T aY)
	{
		setY(Coordinate&lt;T&gt;::getY() + aY);
	}

	template &lt;class T&gt;
	void Vector&lt;T&gt;::add(T aX, T aY)
	{
		addX(aX);
		addY(aY);
	}

}

#endif
</code></pre>
<pre><code class="language-cpp">//coordinate.h
#ifndef _COORDINATE_H
#define _COORDINATE_H

#include &lt;stdexcept&gt;
#include &lt;iostream&gt;

namespace VR
{

	template &lt;class T&gt;
	class Coordinate
	{
		public:
			Coordinate();
			Coordinate(T initX, T initY);
			~Coordinate();

			T&amp; operator[](int index);
		protected:
			T x, y;
	};

	template &lt;class T&gt;
	Coordinate&lt;T&gt;::Coordinate()
	{
	}

	template &lt;class T&gt;
	Coordinate&lt;T&gt;::Coordinate(T initX, T initY)
	:x(initX), y(initY)
	{
	}

	template &lt;class T&gt;
	Coordinate&lt;T&gt;::~Coordinate()
	{
	}

	template &lt;class T&gt;
	T&amp; Coordinate&lt;T&gt;::operator[](int index)
	{
		if (index == 0)
			return x;
		if (index == 1)
			return y;
		else
			throw &quot;out of range in a Coordinate or a erived class&quot;;
	}

}

#endif
</code></pre>
<pre><code class="language-cpp">//main.cc
#include &lt;iostream&gt;
#include &quot;../include/entity.h&quot;
#include &quot;../include/vector.h&quot;
#include &quot;../include/fair_container.h&quot;
int main()
{
	VR::Entity&lt;float&gt; a(1,2,3, 4), b(5,6,7,8);

	std::cout &lt;&lt; a.getPosition()[0] &lt;&lt; ' ' &lt;&lt; a.getPosition()[1] &lt;&lt; std::endl;

	return 0;
}
</code></pre>
<p>Fehler:</p>
<pre><code>../include/entity.h:62: error: ‘void VR::Entity&lt;T&gt;::accelerate(VR::Vector&lt;T&gt;) [with T = int]’ cannot be overloaded
../include/entity.h:25: error: with ‘void VR::Entity&lt;T&gt;::accelerate(VR::Vector&lt;T&gt;) [with T = int]’
../include/entity.h:68: error: ‘void VR::Entity&lt;T&gt;::step() [with T = int]’ cannot be overloaded
../include/entity.h:26: error: with ‘void VR::Entity&lt;T&gt;::step() [with T = int]’
</code></pre>
<p>wenn ich einfach zwei int-vectoren anlegen und dies mit += addiere funktionier t alles:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;../include/entity.h&quot;
#include &quot;../include/vector.h&quot;
#include &quot;../include/fair_container.h&quot;
int main()
{
	VR::Vector&lt;int&gt; a(1,2), b(3,4);

	a += b;

	std::cout &lt;&lt; a[0] &lt;&lt; ' ' &lt;&lt; a[1] &lt;&lt; std::endl;

	return 0;
}
</code></pre>
<p>Ausgabe damit:</p>
<pre><code>EXECUTING:
/home/mambokurt/Projects/VectorRace/src/vectorrace 
----------------------------------------------
4 6

----------------------------------------------
Program exited successfully with errcode (0)
Press the Enter key to close this terminal ...
</code></pre>
<p>was bedeutet das? wie bekomme ich das geregelt?</p>
<p>[Edit]<br />
das scheint also irgendwie an den namen zu liegen.<br />
wenn ich die beiden methoden umbenenne - zB in kop und musch - dann kompiliert er ohne probleme.<br />
wenn ich jetzt noch wüsste, warum er step() und accelerate() als namen nicht annimmet, dann wäre ich ein glücklicher mann.<br />
[/Edit]</p>
<p>mfG MamboKurt</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/161448/fehler-methode-with-t-int-cannot-be-overloaded</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 19:59:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/161448.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 Oct 2006 16:08:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fehler: methode [with T = int] cannot be overloaded on Fri, 06 Oct 2006 16:48:53 GMT]]></title><description><![CDATA[<p>hmm ja also ich bin grad dabei ein paar templateklassen zu schreiben. bis jetzt hat auch alles funktioniert. leider sagt er mir jetzt &quot;methode [with T = int] cannot be overloaded&quot;</p>
<pre><code class="language-cpp">//entity.h
#ifndef _ENTITY_H
#define _ENTITY_H

#include &quot;vector.h&quot;

namespace VR
{

	template &lt;class T&gt;
	class Entity
	{
		public:
			Entity(T intiX, T initY, T initXSpeed, T initYSpeed);
			Entity(Vector&lt;T&gt; initPosition, Vector&lt;T&gt; initSpeed);
			~Entity();

			void accelerate(Vector&lt;T&gt; acc);
			void step();

			const Vector&lt;T&gt; getPosition();
			const Vector&lt;T&gt; getSpeed();

		private:
			Entity();
			void accelerate(Vector&lt;T&gt; acc);
			void step();

			Vector&lt;T&gt; position, speed;
	};

	template &lt;class T&gt;
	Entity&lt;T&gt;::Entity()
	{
	}

	template &lt;class T&gt;
	Entity&lt;T&gt;::Entity(T initX, T initY, T initXSpeed, T initYSpeed)
	:position(Vector&lt;T&gt;(initX, initY)), speed(Vector&lt;T&gt;(initXSpeed, initYSpeed))
	{
	}

	template &lt;class T&gt;
	Entity&lt;T&gt;::Entity(Vector&lt;T&gt; initPosition, Vector&lt;T&gt; initSpeed)
	:position(initPosition), speed(initSpeed)
	{
	}

	template &lt;class T&gt;
	Entity&lt;T&gt;::~Entity()
	{
	}

	template &lt;class T&gt;
	void Entity&lt;T&gt;::accelerate(Vector&lt;T&gt; acc) //hier meckert er (fehler genauer weiter unten)
	{
		speed += acc;
	}

	template &lt;class T&gt;
	void Entity&lt;T&gt;::step() //und hier meckert er (fehler genauer weiter unten)
	{
		position += speed;
	}

	template &lt;class T&gt;
	const Vector&lt;T&gt; Entity&lt;T&gt;::getPosition()
	{
		return position;
	}

	template &lt;class T&gt;
	const Vector&lt;T&gt; Entity&lt;T&gt;::getSpeed()
	{
		return speed;
	}
}
</code></pre>
<pre><code class="language-cpp">//vector.h
#ifndef _VECTOR_H
#define _VECTOR_H

#include &quot;coordinate.h&quot;

namespace VR
{

	template &lt;class T&gt;
	class Vector : public Coordinate&lt;T&gt;
	{
		public:
			Vector();
			Vector(T initX, T initY);
			~Vector();

			void operator+=(Coordinate&lt;T&gt; aCoordinate);

			void addX(T aX);
			void addY(T aY);
			void add(T aX, T aY);
	};

	template &lt;class T&gt;
	Vector&lt;T&gt; ::Vector()
	{
	}

	template &lt;class T&gt;
	Vector&lt;T&gt;::Vector(T initX, T initY)
	{
		Coordinate&lt;T&gt;::x = initX;
		Coordinate&lt;T&gt;::y = initY;
	}

	template &lt;class T&gt;
	Vector&lt;T&gt;::~Vector()
	{
	}

	template &lt;class T&gt;
	void Vector&lt;T&gt;::operator+=(Coordinate&lt;T&gt; aCoordinate)
	{
		Coordinate&lt;T&gt;::x += aCoordinate[0];
		Coordinate&lt;T&gt;::y += aCoordinate[1];
	}

	template &lt;class T&gt;
	void Vector&lt;T&gt;::addX(T aX)
	{
		setX(Coordinate&lt;T&gt;::getX() + aX);
	}

	template &lt;class T&gt;
	void Vector&lt;T&gt;::addY(T aY)
	{
		setY(Coordinate&lt;T&gt;::getY() + aY);
	}

	template &lt;class T&gt;
	void Vector&lt;T&gt;::add(T aX, T aY)
	{
		addX(aX);
		addY(aY);
	}

}

#endif
</code></pre>
<pre><code class="language-cpp">//coordinate.h
#ifndef _COORDINATE_H
#define _COORDINATE_H

#include &lt;stdexcept&gt;
#include &lt;iostream&gt;

namespace VR
{

	template &lt;class T&gt;
	class Coordinate
	{
		public:
			Coordinate();
			Coordinate(T initX, T initY);
			~Coordinate();

			T&amp; operator[](int index);
		protected:
			T x, y;
	};

	template &lt;class T&gt;
	Coordinate&lt;T&gt;::Coordinate()
	{
	}

	template &lt;class T&gt;
	Coordinate&lt;T&gt;::Coordinate(T initX, T initY)
	:x(initX), y(initY)
	{
	}

	template &lt;class T&gt;
	Coordinate&lt;T&gt;::~Coordinate()
	{
	}

	template &lt;class T&gt;
	T&amp; Coordinate&lt;T&gt;::operator[](int index)
	{
		if (index == 0)
			return x;
		if (index == 1)
			return y;
		else
			throw &quot;out of range in a Coordinate or a erived class&quot;;
	}

}

#endif
</code></pre>
<pre><code class="language-cpp">//main.cc
#include &lt;iostream&gt;
#include &quot;../include/entity.h&quot;
#include &quot;../include/vector.h&quot;
#include &quot;../include/fair_container.h&quot;
int main()
{
	VR::Entity&lt;float&gt; a(1,2,3, 4), b(5,6,7,8);

	std::cout &lt;&lt; a.getPosition()[0] &lt;&lt; ' ' &lt;&lt; a.getPosition()[1] &lt;&lt; std::endl;

	return 0;
}
</code></pre>
<p>Fehler:</p>
<pre><code>../include/entity.h:62: error: ‘void VR::Entity&lt;T&gt;::accelerate(VR::Vector&lt;T&gt;) [with T = int]’ cannot be overloaded
../include/entity.h:25: error: with ‘void VR::Entity&lt;T&gt;::accelerate(VR::Vector&lt;T&gt;) [with T = int]’
../include/entity.h:68: error: ‘void VR::Entity&lt;T&gt;::step() [with T = int]’ cannot be overloaded
../include/entity.h:26: error: with ‘void VR::Entity&lt;T&gt;::step() [with T = int]’
</code></pre>
<p>wenn ich einfach zwei int-vectoren anlegen und dies mit += addiere funktionier t alles:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;../include/entity.h&quot;
#include &quot;../include/vector.h&quot;
#include &quot;../include/fair_container.h&quot;
int main()
{
	VR::Vector&lt;int&gt; a(1,2), b(3,4);

	a += b;

	std::cout &lt;&lt; a[0] &lt;&lt; ' ' &lt;&lt; a[1] &lt;&lt; std::endl;

	return 0;
}
</code></pre>
<p>Ausgabe damit:</p>
<pre><code>EXECUTING:
/home/mambokurt/Projects/VectorRace/src/vectorrace 
----------------------------------------------
4 6

----------------------------------------------
Program exited successfully with errcode (0)
Press the Enter key to close this terminal ...
</code></pre>
<p>was bedeutet das? wie bekomme ich das geregelt?</p>
<p>[Edit]<br />
das scheint also irgendwie an den namen zu liegen.<br />
wenn ich die beiden methoden umbenenne - zB in kop und musch - dann kompiliert er ohne probleme.<br />
wenn ich jetzt noch wüsste, warum er step() und accelerate() als namen nicht annimmet, dann wäre ich ein glücklicher mann.<br />
[/Edit]</p>
<p>mfG MamboKurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1150699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1150699</guid><dc:creator><![CDATA[MamboKurt]]></dc:creator><pubDate>Fri, 06 Oct 2006 16:48:53 GMT</pubDate></item><item><title><![CDATA[Reply to fehler: methode [with T = int] cannot be overloaded on Fri, 06 Oct 2006 16:55:29 GMT]]></title><description><![CDATA[<p>hast sich erledigt.<br />
ich war so blöd und hab übersehen, dass ich in der klasse die methoden zweimal eingetragen hatte. einmal unter public einaml unter private.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1150732</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1150732</guid><dc:creator><![CDATA[MamboKurt]]></dc:creator><pubDate>Fri, 06 Oct 2006 16:55:29 GMT</pubDate></item></channel></rss>