<?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[[gelöst] Linkerfehler bei Destruktor]]></title><description><![CDATA[<p>EDIT:<br />
Ich war zu blind zu sehen das ich diese Funktionen nur deklariert aber nicht definiert hatte...</p>
<p>Bei folgendem Code</p>
<pre><code class="language-cpp">#ifndef SHAPES_H_
#define SHAPES_H_

#include &lt;string&gt;
#include &lt;cassert&gt;

class AbstractShape
{
public:
	AbstractShape(void);
	virtual ~AbstractShape(void);

	virtual double area () const = 0;

	void setDescription(std::string const &amp; str)
	{
		m_description = str;
	}
private:
	std::string m_description;
};

class RectShape : public AbstractShape
{
public:
	RectShape(void) : AbstractShape(), m_width(0), m_height(0)
	{
			setDescription(&quot;Rectangular Shape&quot;);
	}

	RectShape(const RectShape &amp; s) 
	{
		this-&gt;m_width = s.m_width;
		this-&gt;m_height = s.m_height;
	}

	const RectShape&amp; operator=(const RectShape&amp; rhs)
	{
		if (this != &amp;rhs) 
		{
			this-&gt;m_width = rhs.m_width;
			this-&gt;m_height = rhs.m_height;
		}
		return *this; // return self-reference so cascaded assignment works
	}

	virtual ~RectShape(void);

	void setSize(double width, double height)
	{
		setWidth(width);
		setHeight(height);
	}

	void setWidth(double width)
	{
		assert(width &gt; 0);
		m_width = width;
	}
	void setHeight(double height)
	{
		assert(height &gt; 0);
		m_height = height;
	}

	double area () const
	{
		return (m_width * m_height);
	}

private:
	double m_width;
	double m_height;

};

#endif
</code></pre>
<p>und</p>
<pre><code class="language-cpp">// main.cpp 
#include &quot;Shapes.h&quot;
int main(int argc, char** argv)
{
	RectShape rectShape;	
}
</code></pre>
<p>bekomme ich die Linkerfehler:</p>
<blockquote>
<p>1&gt;main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;public: virtual __thiscall AbstractShape::~AbstractShape(void)&quot; (??1AbstractShape@@UAE@XZ)&quot; in Funktion &quot;__unwindfunclet$??0RectShape@@QAE@XZ$0&quot;.<br />
1&gt;main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;public: __thiscall AbstractShape::AbstractShape(void)&quot; (??0AbstractShape@@QAE@XZ)&quot; in Funktion &quot;&quot;public: __thiscall RectShape::RectShape(void)&quot; (??0RectShape@@QAE@XZ)&quot;.<br />
1&gt;main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;public: virtual __thiscall RectShape::~RectShape(void)&quot; (??1RectShape@@UAE@XZ)&quot; in Funktion &quot;&quot;public: virtual void * __thiscall RectShape::`scalar deleting destructor'(unsigned int)&quot; (??_GRectShape@@UAEPAXI@Z)&quot;.</p>
</blockquote>
<p>warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/233756/gelöst-linkerfehler-bei-destruktor</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 18:15:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/233756.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 08 Feb 2009 19:36:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [gelöst] Linkerfehler bei Destruktor on Sun, 08 Feb 2009 19:38:28 GMT]]></title><description><![CDATA[<p>EDIT:<br />
Ich war zu blind zu sehen das ich diese Funktionen nur deklariert aber nicht definiert hatte...</p>
<p>Bei folgendem Code</p>
<pre><code class="language-cpp">#ifndef SHAPES_H_
#define SHAPES_H_

#include &lt;string&gt;
#include &lt;cassert&gt;

class AbstractShape
{
public:
	AbstractShape(void);
	virtual ~AbstractShape(void);

	virtual double area () const = 0;

	void setDescription(std::string const &amp; str)
	{
		m_description = str;
	}
private:
	std::string m_description;
};

class RectShape : public AbstractShape
{
public:
	RectShape(void) : AbstractShape(), m_width(0), m_height(0)
	{
			setDescription(&quot;Rectangular Shape&quot;);
	}

	RectShape(const RectShape &amp; s) 
	{
		this-&gt;m_width = s.m_width;
		this-&gt;m_height = s.m_height;
	}

	const RectShape&amp; operator=(const RectShape&amp; rhs)
	{
		if (this != &amp;rhs) 
		{
			this-&gt;m_width = rhs.m_width;
			this-&gt;m_height = rhs.m_height;
		}
		return *this; // return self-reference so cascaded assignment works
	}

	virtual ~RectShape(void);

	void setSize(double width, double height)
	{
		setWidth(width);
		setHeight(height);
	}

	void setWidth(double width)
	{
		assert(width &gt; 0);
		m_width = width;
	}
	void setHeight(double height)
	{
		assert(height &gt; 0);
		m_height = height;
	}

	double area () const
	{
		return (m_width * m_height);
	}

private:
	double m_width;
	double m_height;

};

#endif
</code></pre>
<p>und</p>
<pre><code class="language-cpp">// main.cpp 
#include &quot;Shapes.h&quot;
int main(int argc, char** argv)
{
	RectShape rectShape;	
}
</code></pre>
<p>bekomme ich die Linkerfehler:</p>
<blockquote>
<p>1&gt;main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;public: virtual __thiscall AbstractShape::~AbstractShape(void)&quot; (??1AbstractShape@@UAE@XZ)&quot; in Funktion &quot;__unwindfunclet$??0RectShape@@QAE@XZ$0&quot;.<br />
1&gt;main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;public: __thiscall AbstractShape::AbstractShape(void)&quot; (??0AbstractShape@@QAE@XZ)&quot; in Funktion &quot;&quot;public: __thiscall RectShape::RectShape(void)&quot; (??0RectShape@@QAE@XZ)&quot;.<br />
1&gt;main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;public: virtual __thiscall RectShape::~RectShape(void)&quot; (??1RectShape@@UAE@XZ)&quot; in Funktion &quot;&quot;public: virtual void * __thiscall RectShape::`scalar deleting destructor'(unsigned int)&quot; (??_GRectShape@@UAEPAXI@Z)&quot;.</p>
</blockquote>
<p>warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1660146</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1660146</guid><dc:creator><![CDATA[pospiech]]></dc:creator><pubDate>Sun, 08 Feb 2009 19:38:28 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Linkerfehler bei Destruktor on Sun, 08 Feb 2009 19:40:16 GMT]]></title><description><![CDATA[<p>Weil du den Destruktor deklarierst, aber nicht implementierst. Klar beschwert sich da der Linker...<br />
Denn der Destruktor wird ja definitiv gebraucht, um die Instanz wieder geregelt ins Nirvana zu befördern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1660148</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1660148</guid><dc:creator><![CDATA[franz]]></dc:creator><pubDate>Sun, 08 Feb 2009 19:40:16 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Linkerfehler bei Destruktor on Mon, 09 Feb 2009 00:13:07 GMT]]></title><description><![CDATA[<p>Das Gleiche gilt für den Konstruktor und den anderen Destruktor. Aber dazu müsste man die Fehlermeldung lesen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1660260</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1660260</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 09 Feb 2009 00:13:07 GMT</pubDate></item></channel></rss>