Hey All,

I've been stumbling into the same (annoying little) problem a couple of times, and I'd like to find out how to fix it properly.

Pseudo code

// file A.hpp
#include "classB.hpp"
class A { A() };


// file A.cpp
A::A() { }
// file B.hpp
#include "classA.hpp"
class B { B() };


// file B.cpp
B::B() { }

Notice how they're basically two normal classes, except that the both include the other.
I do have #ifndef CLASS_A / CLASS_B in the headers (header gaurds).

If i do #include "classA.hpp" in file classB.cpp I get errors like so:
error: ‘A’ was not declared in this scope

If I do a dummy class class B; then I can't use any of the functions in that class, because it complains that the class doesn't have that functionality.

Help apprecicatied, as I'm not sure how to design for such a situation... :)
-Harry

i hope this could be helpful

#include <iostream>
using namespace std;

class A;

class B{
	A *obj;
public :
	B(){obj=0;}
	~B(){if(obj)delete obj;}
	void helloFromA();
};
class A{
public :
	void hello()
	{
		cout<<"hello from A"<<endl;
	}
};


void B::helloFromA()
{
	if(!obj)
	{
		obj=new A();;
	}
	obj->hello();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.