# Help with the order of defining classes?

## Recommended Posts

UselessRob    122
Howdy I've got a problem. And I would think it's common but I can't find the solution. It's probably an amateur, newb, beat me in an alley with a stick if you ever find me, type question, but I'm going to be brave and ask it anyway. I have 2 classes in a program that have functions that take each other as input. But how do I define that so it works? I'll try and make it make sense. I have CLASSA and it has a function EatWeasels(CLASSB *b) like that. and CLASSB has a function LeprechaunSoup(CLASSA *a). The problem is the compiler complains because when CLASSA is defined CLASSB hasn't yet been defined. There must be a way around it tho? There just has to be. And it's probably simple. And I'm probably just stupid. But I definately need help! Thanks! Rob.

##### Share on other sites
TangentZ    450

// In A.hclass B;  // Forward declarationclass A    {    public:        void EatWeasels(B *b);   }// end// In A.cpp#include "A.h"#include "B.h"void A::EatWeasels(B *b) { /* blah */ }// In B.hclass A;  // Forward declarationclass B    {    public:        void LeprechaunSoup(A *a);    }// end// In B.cpp#include "B.h"#include "A.h"void B::LeprechaunSoup(A *a) { /* blah */ }

##### Share on other sites
UselessRob    122
Thanks for the quick response! I knew it'd be something simple.

Thanks!

Rob.