View Single Post
Old Feb 22nd, 2008, 10:10 AM   #1
deanosrs
Programmer
 
deanosrs's Avatar
 
Join Date: Apr 2006
Location: Bristol, UK
Posts: 31
Rep Power: 0 deanosrs is on a distinguished road
Send a message via MSN to deanosrs
two classes, call each others functions - how?!!

Hi,
I'm just trying to get two classes to succesfully be able to call functions within each others class. So I effectively have:
// in A's header file
class A {
public:
  B *b;
  void a_function(); // in this function, there's the line b->b_function2
  void a_function2();
};

// in B's header file
class B {
public:
  A *a;
  void b_function(); // in this function, there's the line a->a_function2
  void b_function2();
};
The problem I have at the moment is that I have to include in each header file, the other header file, which it doesn't like. I've also tried forward class definitions, but this doesn't work either, because the line class B; in A's header file isn't sufficient to tell A that B has a function called b_function2().

Any ideas? This has troubled me for a while and is a very difficult problem to google!!
deanosrs is offline   Reply With Quote