<?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[Problem mit der forward-deklaration]]></title><description><![CDATA[<p>Hi hab da ein Problem mit der Forward-Deklaration. So ungefähr sehen meine Klassen aus:</p>
<p>ui_alert.h</p>
<pre><code>#ifndef UI_ALERT_H
#define UI_ALERT_H

#include &lt;QtCore/QVariant&gt;
#include &lt;QtGui/QAction&gt;
#include &lt;QtGui/QApplication&gt;
#include &lt;QtGui/QButtonGroup&gt;
#include &lt;QtGui/QFrame&gt;
#include &lt;QtGui/QLabel&gt;
#include &lt;QtGui/QMainWindow&gt;
#include &lt;QtGui/QPushButton&gt;
#include &lt;QtGui/QWidget&gt;
#include &lt;QObject&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;

using namespace std;
class Funktionen;					&lt;==== Zeile 23
class Ui_AlertWindow : public QObject
{
	Q_OBJECT

public slots:
	void ok()
	{
		Functions-&gt;ausfuehren();		&lt;==== Zeile 48
	}

public:
	QWidget *centralwidget;
	QPushButton *btnOk;
	QLabel *lblUeberschrift;
	Funktionen* Functions;

	void setObject(Funktionen* funct){
		Functions = funct;
	}

	void setupUi(QMainWindow *MainWindow)
	{
	...........
	...........
	........... 
	...........
	...........

	MainWindow-&gt;setCentralWidget(centralwidget);

	retranslateUi(MainWindow);

	QSize size(516, 132);
	size = size.expandedTo(MainWindow-&gt;minimumSizeHint());
	MainWindow-&gt;resize(size);
	MainWindow-&gt;setMinimumWidth(516);
	MainWindow-&gt;setMinimumHeight(132);
	MainWindow-&gt;setMaximumWidth(516);
	MainWindow-&gt;setMaximumHeight(132);

	QObject::connect(btnOk, SIGNAL(clicked()), this, SLOT(ok()));
	QMetaObject::connectSlotsByName(MainWindow);
	} // setupUi

	...............
	..............	
	...............
	................
	..................
	................
	...............
	..................
	...................
	...................
	..................

};

#include &quot;funktionen.h&quot;

namespace Ui {
    class AlertWindow: public Ui_AlertWindow {};

} // namespace Ui

#endif // UI_ALERT_H
</code></pre>
<p>funktionen.h</p>
<pre><code>#ifndef FUNKTIONEN_H
#define FUNKTIONEN_H

#include &lt;QFile&gt;
#include &lt;QMainWindow&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;QFileInfo&gt;
#include &lt;QDateTime&gt;

#include &quot;ui_gui.h&quot;
#include &quot;ui_alert.h&quot;

#include &lt;sys/stat.h&gt;
#include &lt;time.h&gt;
#include &lt;unistd.h&gt;
#include &lt;string&gt;
#include &lt;QString&gt;
#include &lt;QDir&gt;

using namespace std;

class Funktionen
{
	private:
		..............
		.............
		..............
		.............
		..............
		..............

	public:
		Funktionen();
		~Funktionen();
		void displayGUI();
		void ausfuehren();
		void uebergebeObjekt();
		Ui::AlertWindow alert;
		Ui::MainWindow ui;
};

void Funktionen::uebergebeObjekt()
{
	alert.setObject(this);
}

void Funktionen::displayGUI()
{
	//Initialisieren der GUI
	QMainWindow *window = new QMainWindow();
    	alert.setupUi(window);
	window-&gt;show();
}

void Funktionen::ausfuehren()
{
	//Das soll es später einfach ausführen
}

Funktionen::Funktionen()
{

}

Funktionen::~Funktionen()
{

}

#endif
</code></pre>
<p>main.cpp</p>
<pre><code>#include &lt;QApplication&gt;
#include &quot;funktionen.h&quot;

int main(int argc, char *argv[])
{
	Funktionen test;	
	QApplication app(argc, argv);	
	test.uebergebeObjekt();			
	test.displayGUI();			//hier initialisiert es die grafische Benutzeroberfläche
}
</code></pre>
<p>Beim compilieren bekomme ich diese Fehlermeldungen:<br />
ui_alert.h: In member function <code>void Ui\_AlertWindow::ok()': ui_alert.h:48: error: invalid use of undefined type</code>struct Funktionen'<br />
ui_alert.h:23: error: forward declaration of `struct Funktionen'</p>
<p>48: Functions-&gt;ausfuehren();<br />
23: class Funktionen;</p>
<p>Wenn ich Zeile 48 lösche kommen keine Fehlermeldungen.</p>
<p>Könntet ihr mir mal bitte erklären was ich jetzt tun soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/175571/problem-mit-der-forward-deklaration</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 04:53:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/175571.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 12 Mar 2007 08:15:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit der forward-deklaration on Mon, 12 Mar 2007 08:15:00 GMT]]></title><description><![CDATA[<p>Hi hab da ein Problem mit der Forward-Deklaration. So ungefähr sehen meine Klassen aus:</p>
<p>ui_alert.h</p>
<pre><code>#ifndef UI_ALERT_H
#define UI_ALERT_H

#include &lt;QtCore/QVariant&gt;
#include &lt;QtGui/QAction&gt;
#include &lt;QtGui/QApplication&gt;
#include &lt;QtGui/QButtonGroup&gt;
#include &lt;QtGui/QFrame&gt;
#include &lt;QtGui/QLabel&gt;
#include &lt;QtGui/QMainWindow&gt;
#include &lt;QtGui/QPushButton&gt;
#include &lt;QtGui/QWidget&gt;
#include &lt;QObject&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;

using namespace std;
class Funktionen;					&lt;==== Zeile 23
class Ui_AlertWindow : public QObject
{
	Q_OBJECT

public slots:
	void ok()
	{
		Functions-&gt;ausfuehren();		&lt;==== Zeile 48
	}

public:
	QWidget *centralwidget;
	QPushButton *btnOk;
	QLabel *lblUeberschrift;
	Funktionen* Functions;

	void setObject(Funktionen* funct){
		Functions = funct;
	}

	void setupUi(QMainWindow *MainWindow)
	{
	...........
	...........
	........... 
	...........
	...........

	MainWindow-&gt;setCentralWidget(centralwidget);

	retranslateUi(MainWindow);

	QSize size(516, 132);
	size = size.expandedTo(MainWindow-&gt;minimumSizeHint());
	MainWindow-&gt;resize(size);
	MainWindow-&gt;setMinimumWidth(516);
	MainWindow-&gt;setMinimumHeight(132);
	MainWindow-&gt;setMaximumWidth(516);
	MainWindow-&gt;setMaximumHeight(132);

	QObject::connect(btnOk, SIGNAL(clicked()), this, SLOT(ok()));
	QMetaObject::connectSlotsByName(MainWindow);
	} // setupUi

	...............
	..............	
	...............
	................
	..................
	................
	...............
	..................
	...................
	...................
	..................

};

#include &quot;funktionen.h&quot;

namespace Ui {
    class AlertWindow: public Ui_AlertWindow {};

} // namespace Ui

#endif // UI_ALERT_H
</code></pre>
<p>funktionen.h</p>
<pre><code>#ifndef FUNKTIONEN_H
#define FUNKTIONEN_H

#include &lt;QFile&gt;
#include &lt;QMainWindow&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;QFileInfo&gt;
#include &lt;QDateTime&gt;

#include &quot;ui_gui.h&quot;
#include &quot;ui_alert.h&quot;

#include &lt;sys/stat.h&gt;
#include &lt;time.h&gt;
#include &lt;unistd.h&gt;
#include &lt;string&gt;
#include &lt;QString&gt;
#include &lt;QDir&gt;

using namespace std;

class Funktionen
{
	private:
		..............
		.............
		..............
		.............
		..............
		..............

	public:
		Funktionen();
		~Funktionen();
		void displayGUI();
		void ausfuehren();
		void uebergebeObjekt();
		Ui::AlertWindow alert;
		Ui::MainWindow ui;
};

void Funktionen::uebergebeObjekt()
{
	alert.setObject(this);
}

void Funktionen::displayGUI()
{
	//Initialisieren der GUI
	QMainWindow *window = new QMainWindow();
    	alert.setupUi(window);
	window-&gt;show();
}

void Funktionen::ausfuehren()
{
	//Das soll es später einfach ausführen
}

Funktionen::Funktionen()
{

}

Funktionen::~Funktionen()
{

}

#endif
</code></pre>
<p>main.cpp</p>
<pre><code>#include &lt;QApplication&gt;
#include &quot;funktionen.h&quot;

int main(int argc, char *argv[])
{
	Funktionen test;	
	QApplication app(argc, argv);	
	test.uebergebeObjekt();			
	test.displayGUI();			//hier initialisiert es die grafische Benutzeroberfläche
}
</code></pre>
<p>Beim compilieren bekomme ich diese Fehlermeldungen:<br />
ui_alert.h: In member function <code>void Ui\_AlertWindow::ok()': ui_alert.h:48: error: invalid use of undefined type</code>struct Funktionen'<br />
ui_alert.h:23: error: forward declaration of `struct Funktionen'</p>
<p>48: Functions-&gt;ausfuehren();<br />
23: class Funktionen;</p>
<p>Wenn ich Zeile 48 lösche kommen keine Fehlermeldungen.</p>
<p>Könntet ihr mir mal bitte erklären was ich jetzt tun soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1243761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1243761</guid><dc:creator><![CDATA[KingV1k]]></dc:creator><pubDate>Mon, 12 Mar 2007 08:15:00 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit der forward-deklaration on Mon, 12 Mar 2007 08:22:13 GMT]]></title><description><![CDATA[<p>KingV1k schrieb:</p>
<blockquote>
<p>Beim compilieren bekomme ich diese Fehlermeldungen:<br />
ui_alert.h: In member function <code>void Ui\_AlertWindow::ok()': ui_alert.h:48: error: invalid use of undefined type</code>struct Funktionen'<br />
ui_alert.h:23: error: forward declaration of `struct Funktionen'</p>
</blockquote>
<p>Natürlich, der Compiler weiß nur dass es <code>Funktionen</code> gibt, nicht wie die Klasse aussieht. Implementiere den <code>ok</code> -Slot einfach in der cpp-Datei, und den ganzen (nicht-trivialen) Rest am besten auch gleich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1243763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1243763</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Mon, 12 Mar 2007 08:22:13 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit der forward-deklaration on Mon, 12 Mar 2007 08:24:26 GMT]]></title><description><![CDATA[<p>Mit der Forward-Deklaration kennt der Compiler nur den Namen der Klasse - das reicht nicht aus, um deren Methoden aufrufen zu können (oder Objekte von dem Typ anzulegen). Damit Zeile 48 funktionieren kann, brauchst du die komplette Klassendefinition.</p>
<p>wenn du in der &quot;funktionen.h&quot; kein Ui_Alertwindow benötigst, solltest du die #includes umdrehen, andernfalls geht folgendes:</p>
<pre><code class="language-cpp">class Funktionen;

class Ui_Alertwindow : public CObject
{
  ...
public:
  void ok();
  ...
};

#include &quot;funktionen.h&quot;

inline void Ui_Alertwindow::ok()
{
  Funktions-&gt;ausfuehren();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1243764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1243764</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 12 Mar 2007 08:24:26 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit der forward-deklaration on Mon, 12 Mar 2007 08:27:55 GMT]]></title><description><![CDATA[<p>tut mir leid, aber ich versteh nicht wie du es meinst mit den ok-Slot in die cpp zu implementieren. könntest du es mal genauer erklären?</p>
<p>edit:<br />
achso hab den beitrag von CStoll zu spät mitbekommen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1243766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1243766</guid><dc:creator><![CDATA[KingV1k]]></dc:creator><pubDate>Mon, 12 Mar 2007 08:27:55 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit der forward-deklaration on Mon, 12 Mar 2007 10:35:12 GMT]]></title><description><![CDATA[<p>Jetzt hab ich alle Methoden in der Datei ui_alert.h bearbeitet wie es CStoll gesagt hat, aber irgendwie will es noch immer nicht funktionieren. Selbe Fehlermeldungen nur andere Spalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1243841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1243841</guid><dc:creator><![CDATA[KingV1k]]></dc:creator><pubDate>Mon, 12 Mar 2007 10:35:12 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit der forward-deklaration on Mon, 12 Mar 2007 11:19:43 GMT]]></title><description><![CDATA[<p>KingV1k schrieb:</p>
<blockquote>
<p>Jetzt hab ich alle Methoden in der Datei ui_alert.h bearbeitet wie es CStoll gesagt hat, aber irgendwie will es noch immer nicht funktionieren. Selbe Fehlermeldungen nur andere Spalten.</p>
</blockquote>
<p>Du sollst die Implementationen in die &quot;ui_alert.<strong>cpp</strong>&quot; packen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1243874</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1243874</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Mon, 12 Mar 2007 11:19:43 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit der forward-deklaration on Mon, 12 Mar 2007 12:47:10 GMT]]></title><description><![CDATA[<p>ok. hab ich gemacht aber es kommt jetzt diese Fehlermeldung:<br />
release\main.o:main.cpp:(.text+0x0): first defined here<br />
release\ui_alert.o:ui_alert.cpp:(.text+0x220): multiple definition of `Funktionen::ausfuehren()'</p>
<p>und das für jede einzelne Methode in meiner Klasse Funktionen. was jetzt? hat jemand eine idee woher das kommt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1243946</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1243946</guid><dc:creator><![CDATA[KingV1k]]></dc:creator><pubDate>Mon, 12 Mar 2007 12:47:10 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit der forward-deklaration on Mon, 12 Mar 2007 12:52:14 GMT]]></title><description><![CDATA[<p>Die Methoden der Klasse 'Funktionen' solltest du natürlich auch in ein eigenes CPP-File auslagern (oder inline definieren - aber das lohnt sich nur bei sehr kleinen Funktionen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1243951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1243951</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 12 Mar 2007 12:52:14 GMT</pubDate></item></channel></rss>