Problems with managed classes

  • Thread starter Thread starter ewpatton
  • Start date Start date
E

ewpatton

I've got two classes, ObjClass1 and ObjClass2. I need them to both
know about one another but I can't include the header twice because of
a "type redefinition" even though it's the same file. Ex:

-----ObjClass1.h-----

#ifndef __OBJCLASS1
#define __OBJCLASS1

#include "ObjClass2.h"

public ref class ObjClass1
{
// Stuff
ObjClass2 ^obj2;
};

#endif


-----ObjClass2.h-----

#ifndef __OBJCLASS2
#define __OBJCLASS2

#include "ObjClass1.h"

public ref class ObjClass2
{
// Stuff
ObjClass1 ^obj1;
};

#endif

Now, with this configuration the compiler just complains that there's
no type ObjClass1 and ObjClass2 for the opposite's header file. So I
tried to undef __OBJCLASS1 in ObjClass2.h to try to fix that problem,
but then it says that I'm redefining ObjClass1 since ObjClass1's
header includes ObjClass2.h which includes ObjClass1 again.

At this point I figured I would just put a forward declaration in each
header:

ref class ObjClass1;

ref class ObjClass2;

But when I do this and try to call a function in the object, the
compiler complains that it has no clue what ObjClass1 and ObjClass2
are.

I'm getting really frustrated by this. Is there any way to fix it?

Evan
 
I've got two classes, ObjClass1 and ObjClass2. I need them to both
know about one another but I can't include the header twice because of
a "type redefinition" even though it's the same file. Ex:

-----ObjClass1.h-----

#ifndef __OBJCLASS1
#define __OBJCLASS1

#include "ObjClass2.h"

public ref class ObjClass1
{
// Stuff
ObjClass2 ^obj2;

};

#endif

-----ObjClass2.h-----

#ifndef __OBJCLASS2
#define __OBJCLASS2

#include "ObjClass1.h"

public ref class ObjClass2
{
// Stuff
ObjClass1 ^obj1;

};

#endif

Now, with this configuration the compiler just complains that there's
no type ObjClass1 and ObjClass2 for the opposite's header file. So I
tried to undef __OBJCLASS1 in ObjClass2.h to try to fix that problem,
but then it says that I'm redefining ObjClass1 since ObjClass1's
header includes ObjClass2.h which includes ObjClass1 again.

At this point I figured I would just put a forward declaration in each
header:

ref class ObjClass1;

ref class ObjClass2;

But when I do this and try to call a function in the object, the
compiler complains that it has no clue what ObjClass1 and ObjClass2
are.

I'm getting really frustrated by this. Is there any way to fix it?

Evan

Never mind I finally stumbled upon the solution
 
Back
Top