Click to See Complete Forum and Search --> : Visul C++ cant find my class.


DiDi
May 10th, 1999, 06:33 AM
In the compiling prozess VC cant find my class whitch is defined in another file. I use the #include ("#include Gegend.h") statement but it dont works. I tried to declare my class at new (In the form "class Gegend;" right before I use it) but it didnt work.

This is my error:
:\programme\microsoft visual studio\myprojects\evolution\anzeige.h(41) : error C2079: 'Geg' uses undefined class 'Gegend'

Gegend is my class and Geg the name of my instanze.


When I try to copy the whole declaration my compiler said "redefinition".

What is my failure ?????

ÖÖÖÖÖ@OOOOOOOOOO00000000ooooooooooo°°°°°.... . . . . . . . . . .

Jason Teagle
May 10th, 1999, 07:39 AM
If you try to paste the whole declaration, it says "Redefinition". This implies that the header file IS being compiled correctly.

The fact that the compilation says "... uses undefined class X" means that AT THE POINT where you tried to use it, the header file hadn't been compiled.

I would guess that you have a method (prototyped in a header file Y.H), which takes a parameter (or returns one) of type X, but X's header has not been included BEFORE Y's header in the list of #includes. This is what I mean:

Class X's header file, X.H:

---
class X
{
private:
CString m_strName ;

public:
X(void);
~X(void);
CString GetName(void) {return m_strName ;};
};


---

Class Y's header file, Y.H:

---
class Y
{
private:
X *m_pX ;

public:
Y(X *pX); // When this header is compiled, it MUST know what
// X is already (i.e., X.H MUST have been included
// before this header file).
~Y(void);
};


---

Class Y's code file, Y.CPP:

---
#include "y.h"
#include "x.h"

Y::Y(X *pX)
{
m_pX = pX ;
}

Y::~Y(void)
{
}


---

In the above example, although X is included in Y's code, when the compiler tries to compile Y's header (which comes first), it is told that there is a method taking an X pointer - at this point, because X.H has not been compiled, it does not know what this means.

The cure for this is to include X BEFORE any header which refers to it.

So, in your compiler output window, look for the CPP file which was being compiled when the error was displayed (the CPP filename appears before any errors generated from it); in that CPP file, make sure GEGEND.H is included BEFORE ANZEIGE.H.

Does that cure it?

DiDi
May 10th, 1999, 07:54 AM
Thank you, it works now !!!

ÖÖÖÖÖ@OOOOOOOOOO00000000ooooooooooo°°°°°.... . . . . . . . . . .