Today, I faced very weird problem. I have 2 classes say class A and B. Both have one .h and .cpp files. 4 files(A.cpp,B.cpp,A.h,B.h). A class is base class of B and we are using instance of B in class A. It was saying "not a type" error while compiling. How can I solve the error? Google was saying "it is a kind of cyclic dependency" in the code that's why it was giving error. Please help. Thanks.
nitin1
15
Master Poster
Recommended Answers
Jump to Postyou have to use forward declarations and pointers.
A.h
#ifndef A_H #define A_H class B; class A { private: B* bclass; public: //... }; #endif
A.cpp
#included "A.h" #included "B.h" // code for class a goes here.
B.h
#ifndef …
Jump to PostChange
#included
to#include
All 6 Replies
NathanOliver
429
Veteran Poster
Featured Poster
Moschops
683
Practically a Master Poster
Featured Poster
nitin1
15
Master Poster
NathanOliver
429
Veteran Poster
Featured Poster
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
NathanOliver
429
Veteran Poster
Featured Poster
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.