Gast
#4373277
Hallo zusammen,
ich habe zwei ganz einfache Headerdateien:
-> one.h von class One und
-> two.h von class Two
Wenn ich schreibe:
--------------------Datei one.h------------------------------
#pragma once
#include "two.h"
class One
{
public:
Two * EinTwoObjekt;
One();
~One();
};
--------------------Datei tow.h------------------------------
#pragma once
#include "one.h"
class Two
{
public:
One * EinOwoObjekt;
Two();
~Two();
};
Dann bekomme ich natürlich einen Fehler!
Warum weil #include "one.h" und #include "two.h",
selbst "one.h" oder "two.h" einbinden.
Also so z.B. :
--------------------Datei one.h------------------------------
#pragma once
// #include "two.h" -> wird durch den Präprozessor ersetzt
....
#include "one.h" -> und hier taucht jetzt "one.h" in der "one.h" auf
.... -> und es kommt zu einem Fehler, oder ?
class Two
{
public:
One * EinOwoObjekt;
Two();
~Two();
};
class One
{
public:
Two * EinTwoObjekt;
One();
~One();
};
--------------------Datei one.h END ------------------------------
Wenn ich aber schreibe:
--------------------Datei one.h------------------------------
#pragma once
#include "two.h"
class Two; // Neu dazugekommen
class One
{
public:
Two * EinTwoObjekt;
One();
~One();
};
--------------------Datei tow.h------------------------------
#pragma once
#include "one.h"
class One; // Neu dazugekommen
class Two
{
public:
One * EinOwoObjekt;
Two();
~Two();
};
wird alles schön Kompiliert!
-> Warum ist das so?
-> Wie würdet Ihr das Problem lösen?
DANKE....
IDE VS2010
Gruß c++