hi
I instaniate object of one class in another and vice-versa. I get errors which seem to be because of dependencies not set right in makefile and the type is not available during instatniation.
error: B.h: error: ISO C++ forbids declaration of ‘A’ with no type
Please give me some suggestions
regardsCode:Makefile : OBJS = main.o A.o B.o .cpp.o: g++ -g -Wno-deprecated -c $< run: $(OBJS) g++ -g -Wno-deprecated -o $@ $(OBJS) main.o: main.cpp A.o: A.cpp B.o: B.cpp //header file A.h #ifndef _A_H_ #define _A_H_ #include "B.h" class A{ A a; //object of class A B b;//object of class B void print(){} } #endif //cpp file A.cpp #include "A.h" void A::print(){ cout << "A" << endl; } //header file B.h #ifndef _B_H_ #define _B_H_ #include "A.h" class B{ A a;//object of class A B b;//object of class B } #endif //cpp file B.cpp #include "B.h" void B::print(){ cout << "B" << endl; }
Kiran


Reply With Quote


Bookmarks