<?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[undefined reference in eigener klasse]]></title><description><![CDATA[<p>also ich hab da ein klassentemplate. das wollte ich nun instanzieren. leider gibt er mir beim linken fehler aus</p>
<pre><code class="language-cpp">// coordinate.h

#ifndef _COORDINATE_H
#define _COORDINATE_H

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

		void setX(T newX);
		void setY(T newY);
		void set(T newX, T newY);

		T getX();
		T getY();
		T* get();

	private:
		T x, y;
};

#endif
</code></pre>
<pre><code class="language-cpp">// coordinate.cc

#include &quot;../include/coordinate.h&quot;

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;
void Coordinate&lt;T&gt;::setX(T newX)
{
	x = newX;
}

template &lt;class T&gt;
void Coordinate&lt;T&gt;::setY(T newY)
{
	y = newY;
}

template &lt;class T&gt;
void Coordinate&lt;T&gt;::set(T newX, T newY)
{
	setX(newX);
	setY(newY);
}

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

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

template &lt;class T&gt;
T* Coordinate&lt;T&gt;::get()
{
	T* temp = new T[2];
	temp[0] = x;
	temp[1] = y;
	return temp;
}
</code></pre>
<pre><code class="language-cpp">// main.cc

#include &lt;iostream&gt;
#include &quot;../include/coordinate.h&quot;

int main()
{
	Coordinate&lt;int&gt; test(20, 30);

	std::cout &lt;&lt; test.getX() &lt;&lt; ' ' &lt;&lt; test.getY() &lt;&lt; std::endl;

	return 0;
}
</code></pre>
<pre><code>main.o in function 'main':
/home/mambokurt/Projects/Test:main.cc:10:undefined reference to Coordinate&lt;int&gt;::Coordinate(int,int)
/home/mambokurt/Projects/Test:main.cc:12:undefined reference to Coordinate&lt;int&gt;::getY()
/home/mambokurt/Projects/Test:main.cc:12:undefined reference to Coordinate&lt;int&gt;::getX()
/home/mambokurt/Projects/Test:main.cc:14:undefined reference to Coordinate&lt;int&gt;::~Coordinate
/home/mambokurt/Projects/Test:main.cc:14:undefined reference to Coordinate&lt;int&gt;::Coordinate
</code></pre>
<p>also irgendwie raff ich net woran das liegt. wenn einer ne ahnung hat: hier rein schreiben.<br />
wens interessiert compiler g++ 3.4.6 (linux)</p>
<p>mfg MamboKurt</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/161267/undefined-reference-in-eigener-klasse</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 21:41:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/161267.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Oct 2006 00:30:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to undefined reference in eigener klasse on Thu, 05 Oct 2006 00:33:25 GMT]]></title><description><![CDATA[<p>also ich hab da ein klassentemplate. das wollte ich nun instanzieren. leider gibt er mir beim linken fehler aus</p>
<pre><code class="language-cpp">// coordinate.h

#ifndef _COORDINATE_H
#define _COORDINATE_H

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

		void setX(T newX);
		void setY(T newY);
		void set(T newX, T newY);

		T getX();
		T getY();
		T* get();

	private:
		T x, y;
};

#endif
</code></pre>
<pre><code class="language-cpp">// coordinate.cc

#include &quot;../include/coordinate.h&quot;

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;
void Coordinate&lt;T&gt;::setX(T newX)
{
	x = newX;
}

template &lt;class T&gt;
void Coordinate&lt;T&gt;::setY(T newY)
{
	y = newY;
}

template &lt;class T&gt;
void Coordinate&lt;T&gt;::set(T newX, T newY)
{
	setX(newX);
	setY(newY);
}

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

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

template &lt;class T&gt;
T* Coordinate&lt;T&gt;::get()
{
	T* temp = new T[2];
	temp[0] = x;
	temp[1] = y;
	return temp;
}
</code></pre>
<pre><code class="language-cpp">// main.cc

#include &lt;iostream&gt;
#include &quot;../include/coordinate.h&quot;

int main()
{
	Coordinate&lt;int&gt; test(20, 30);

	std::cout &lt;&lt; test.getX() &lt;&lt; ' ' &lt;&lt; test.getY() &lt;&lt; std::endl;

	return 0;
}
</code></pre>
<pre><code>main.o in function 'main':
/home/mambokurt/Projects/Test:main.cc:10:undefined reference to Coordinate&lt;int&gt;::Coordinate(int,int)
/home/mambokurt/Projects/Test:main.cc:12:undefined reference to Coordinate&lt;int&gt;::getY()
/home/mambokurt/Projects/Test:main.cc:12:undefined reference to Coordinate&lt;int&gt;::getX()
/home/mambokurt/Projects/Test:main.cc:14:undefined reference to Coordinate&lt;int&gt;::~Coordinate
/home/mambokurt/Projects/Test:main.cc:14:undefined reference to Coordinate&lt;int&gt;::Coordinate
</code></pre>
<p>also irgendwie raff ich net woran das liegt. wenn einer ne ahnung hat: hier rein schreiben.<br />
wens interessiert compiler g++ 3.4.6 (linux)</p>
<p>mfg MamboKurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149605</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149605</guid><dc:creator><![CDATA[MamboKurt]]></dc:creator><pubDate>Thu, 05 Oct 2006 00:33:25 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Thu, 05 Oct 2006 02:13:53 GMT]]></title><description><![CDATA[<p>Tu die gesammte Klasse in die Header. Also nicht header+cpp sondern alles in die Header paken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149611</guid><dc:creator><![CDATA[DEvent]]></dc:creator><pubDate>Thu, 05 Oct 2006 02:13:53 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Thu, 05 Oct 2006 03:47:20 GMT]]></title><description><![CDATA[<p><a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39467.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39467.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149616</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149616</guid><dc:creator><![CDATA[Wofür die FAQ?]]></dc:creator><pubDate>Thu, 05 Oct 2006 03:47:20 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Thu, 05 Oct 2006 08:20:53 GMT]]></title><description><![CDATA[<p>danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149712</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149712</guid><dc:creator><![CDATA[MamboKurt]]></dc:creator><pubDate>Thu, 05 Oct 2006 08:20:53 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Thu, 05 Oct 2006 10:43:52 GMT]]></title><description><![CDATA[<p>verssuch es mal mit makefiles</p>
<p>hier mal nen Beispiel:</p>
<pre><code>CC = g++
OBJ = main.o coordinate.o
APP = Programmname

all: $(OBJ)
	$(CC) -o $(APP) $(OBJ)

.cpp.o:
	$(CC) -c $&lt;

clean:
	rm -rf $(OBJ) $(APP)

main.o: main.cc coordinate.h
coordinate.o: coordinate.cc coordinate.h
</code></pre>
<p>Die funktionsweise dieser makefiles ist einfach:</p>
<p>einfach make eingeben und das was unter all: steht wird ausgeführt.<br />
In den Ersten drei Zeilen sind Variablen definiert, die dann Später mit $(Variablenname) aufgerufen werden. Funktioniert änlich wie ein Makros in C++. Wichtig alles was hier steht miss in eine Datei namens &quot;Makefile&quot;</p>
<p>Dies Makefile hat man mir hal geschrieben, als ich nach der Funktionsweise von Makefiles nachgefragt habe.</p>
<pre><code>CC = g++
OBJ = main.o modul1.o modul2.o
APP = programmname
CFLAGS = $(shell sdl-config --cflags) # evtl auch noch -O2 für Optimierungen, oder -Wall für Warnungen
LDFLAGS = -lm $(shell sdl-config --libs)

# das hauptziel (die syntax ist immer: &quot;ziel: abhängigkeiten\n\tbefehle&quot;, also unbediengt mit dem tab einrücken...)
all: $(OBJ)
   $(CC) $(LDFLAGS) -o $(APP) $(OBJ)

# generelle Regel zum Erzeugen von Objektdateien (.o) aus dem Quellcode (.cpp)
.cpp.o:
   $(CC) $(CFLAGS) -c $&lt;

# das ist ganz nützlich zum Aufräumen ;)
clean:
   rm -rf $(OBJ) $(APP)

# zusätzliche Abhängigkeiten (da make nun schon weiß, wie es aus einer .cpp
# datei zu einer .o Datei kommt, reichen hier einfach die Dateien von denen das
# Modul abhängt. Wenn du dann z.B. eine Headerdatei änderst, dann wird das
# entsprechende Objektfile automatisch neu kompiliert und dann wieder zu dem
# Programm gelinkt.
main.o: main.cpp common.h
modul1.o: modul1.cpp modul1.h common.h
modul2.o: modul2.cpp modul2.h
</code></pre>
<p>Da ist noch SDL und so drin, könntest du auch mal gebrauchen.</p>
<p>So wird übrigens nicht mehr alles neu kompiliert, sondern nur der Teil, an dem Änderungen gemacht wurden. (Beschleunigt das Kompilieren bei größeren Projeten)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149802</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149802</guid><dc:creator><![CDATA[Krux]]></dc:creator><pubDate>Thu, 05 Oct 2006 10:43:52 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Thu, 05 Oct 2006 10:47:56 GMT]]></title><description><![CDATA[<p>Krux schrieb:</p>
<blockquote>
<p>verssuch es mal mit makefiles</p>
</blockquote>
<p>In welchem Bezug steht dieser Tipp jetzt zu dem geäusserten Problem und seiner (vollkommen richtigen) Lösung?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149806</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149806</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 05 Oct 2006 10:47:56 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Thu, 05 Oct 2006 12:38:22 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/11517">@krux</a>: das mit den makefiles hab ich schon raus. ich hatte die klasse erst mit int statt als template geschrieben und da hatte ja alles funktioniert.<br />
da mir DEvent gesagt hat, was zu machen ist funktioniert alles wieder einwandfrei, auch wenn es etwas unschön is meiner ansicht nach.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1149899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1149899</guid><dc:creator><![CDATA[MamboKurt]]></dc:creator><pubDate>Thu, 05 Oct 2006 12:38:22 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Fri, 06 Oct 2006 18:54:19 GMT]]></title><description><![CDATA[<p>hmm ich habe jetzt eine klasse, die von einer kronkretisierung eines templates erbt. gilt das da auch noch? bei mir funktioniert das anders mit header und source irgendwie nicht.<br />
etwa so:</p>
<pre><code class="language-cpp">class Abgeleitet : public TemplateBasisKlass&lt;int&gt;
{
   //fancy stuff here
}
</code></pre>
<p>bin ich einfach zu blöd oder geht das nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1150794</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1150794</guid><dc:creator><![CDATA[MamboKurt]]></dc:creator><pubDate>Fri, 06 Oct 2006 18:54:19 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Fri, 06 Oct 2006 20:42:53 GMT]]></title><description><![CDATA[<p>Beschreib doch mal den Fehler genauer. Denn das sollte schon gehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1150843</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1150843</guid><dc:creator><![CDATA[Apollon]]></dc:creator><pubDate>Fri, 06 Oct 2006 20:42:53 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Sat, 07 Oct 2006 07:26:38 GMT]]></title><description><![CDATA[<p>ja selber fehler wie oben: &quot;undefinede refernce&quot;</p>
<pre><code class="language-cpp">//vrentity.h

#include &quot;entity.h&quot;
#include &quot;vector.h&quot;

namespace VR
{

	enum Acceleration { KEEP, RIGHT, UP, DOWN, LEFT};

	class VREntity : protected Entity&lt;int&gt;
	{
		public:
			VREntity();
			VREntity(int initX, int initY, int initXSpeed, int initYSpeed);
			VREntity(Vector&lt;int&gt; initPosition, Vector&lt;int&gt; initSpeed);
			~VREntity();

			Vector&lt;int&gt; step(Acceleration acc);

			using Entity&lt;int&gt;::getPosition;
			using Entity&lt;int&gt;::getSpeed;
	};

/*	VREntity::VREntity()
	{
		position = Vector&lt;int&gt;(0,0);
		speed = Vector&lt;int&gt;(0,0);
	}

	VREntity::VREntity(int initX, int initY, int initXSpeed, int initYSpeed)
	{
		position = Vector&lt;int&gt;(initX,initY);
		speed = Vector&lt;int&gt;(initXSpeed,initYSpeed);
	}

	VREntity::VREntity(Vector&lt;int&gt; initPosition, Vector&lt;int&gt; initSpeed)
	{
		position = initPosition;
		speed = initSpeed;
	}

	VREntity::~VREntity()
	{
	}

	Vector&lt;int&gt; VREntity::step(Acceleration acc)
	{
		switch (acc)
		{
			case KEEP	: break;
			case RIGHT	: accelerate(Vector&lt;int&gt;(1, 0)); break;
			case UP		: accelerate(Vector&lt;int&gt;(0, 1)); break;
			case LEFT	: accelerate(Vector&lt;int&gt;(-1, 0)); break;
			case DOWN	: accelerate(Vector&lt;int&gt;(0, -1));
		}

		move();

		return position;
	}*/
}
</code></pre>
<pre><code class="language-cpp">#include &quot;../include/vrentity.h&quot;

namespace VR
{

	VREntity::VREntity()
	{
		position = Vector&lt;int&gt;(0,0);
		speed = Vector&lt;int&gt;(0,0);
	}

	VREntity::VREntity(int initX, int initY, int initXSpeed, int initYSpeed)
	{
		position = Vector&lt;int&gt;(initX,initY);
		speed = Vector&lt;int&gt;(initXSpeed,initYSpeed);
	}

	VREntity::VREntity(Vector&lt;int&gt; initPosition, Vector&lt;int&gt; initSpeed)
	{
		position = initPosition;
		speed = initSpeed;
	}

	VREntity::~VREntity()
	{
	}

	Vector&lt;int&gt; VREntity::step(Acceleration acc)
	{
		switch (acc)
		{
			case KEEP	: break;
			case RIGHT	: accelerate(Vector&lt;int&gt;(1, 0)); break;
			case UP		: accelerate(Vector&lt;int&gt;(1, 0)); break;
			case LEFT	: accelerate(Vector&lt;int&gt;(-1, 0)); break;
			case DOWN	: accelerate(Vector&lt;int&gt;(0, -1));
		}

		move();

		return position;
	}
}
</code></pre>
<pre><code class="language-cpp">//main.cc
#include &lt;iostream&gt;
#include &quot;../include/vrentity.h&quot;
#include &quot;../include/vector.h&quot;
#include &quot;../include/fair_container.h&quot;
int main()
{
	VR::VREntity a(0, 0, 1, 1);

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

	a.step(VR::UP);

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

	a.step(VR::RIGHT);

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

	return 0;
}
</code></pre>
<pre><code>/bin/sh ../libtool --tag=CXX --mode=link g++ -Wall -g -g -O2   -o vectorrace  main.o SDLGraphics.o -lSDL 
g++ -Wall -g -g -O2 -o vectorrace main.o SDLGraphics.o  /usr/lib/libSDL.so
main.o: In function `main':/home/mambokurt/Projects/VectorRace/src/main.cc:10: undefined reference to `VR::VREntity::VREntity(int, int, int, int)'
:/home/mambokurt/Projects/VectorRace/src/main.cc:14: undefined reference to `VR::VREntity::step(VR::Acceleration)'
:/home/mambokurt/Projects/VectorRace/src/main.cc:18: undefined reference to `VR::VREntity::step(VR::Acceleration)'
:/home/mambokurt/Projects/VectorRace/src/main.cc:24: undefined reference to `VR::VREntity::~VREntity()'
:/home/mambokurt/Projects/VectorRace/src/main.cc:24: undefined reference to `VR::VREntity::~VREntity()'
collect2: ld returned 1 exit status
make: *** [vectorrace] Error 1
</code></pre>
<p>wenn ich alles in den header schreibe, also die auskommentierung weg lasse, funktioniert alles.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1150897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1150897</guid><dc:creator><![CDATA[MamboKurt]]></dc:creator><pubDate>Sat, 07 Oct 2006 07:26:38 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Sat, 07 Oct 2006 14:32:14 GMT]]></title><description><![CDATA[<p>Gehoert die Implementationsdatei zum Projekt? Wird sie also kompilliert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1151039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1151039</guid><dc:creator><![CDATA[Apollon]]></dc:creator><pubDate>Sat, 07 Oct 2006 14:32:14 GMT</pubDate></item><item><title><![CDATA[Reply to undefined reference in eigener klasse on Sat, 07 Oct 2006 22:08:12 GMT]]></title><description><![CDATA[<p>ja sie gehört zum projekt und wird kompiliert. hab auch schon mal &quot;vo hand&quot; kompiliert und versucht zu linken. hat auch zu keinem erfolg geführt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1151236</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1151236</guid><dc:creator><![CDATA[MamboKurt]]></dc:creator><pubDate>Sat, 07 Oct 2006 22:08:12 GMT</pubDate></item></channel></rss>