i hav classA hence A.h and A.cpp,i hav declared some member variables in A.h and defined/initialized them using object of class A in A.cpp.now i hav class B hence B.h and B.cpp ,now i want to use class A's same object and its member variables (which i hav already initialized) in B.cpp.how do i do it?

Note:for some reasons i hav #included B.h in A.h hence #include A.h in B.h is giving error

11 Years
Discussion Span
Last Post by thekashyap

Do you know about inclusion guards?

// myheader.h
#ifndef MYHEADER_H
#define MYHEADER_H

// Your class here


Most likely the error you're getting is a multiple definition error for classA because you used a header without inclusion guards multiple times.


>> for some reasons i hav #included B.h in A.h hence #include A.h in B.h is giving error.
This should never be done. In any case include guard as Naure described should solve the problem. But I suggest you relook at your dependencies and see how to avoid one of the two #includes.


Ah, and next time copy paste the error msg in your post, it's more understandble than "XYZ is giving error".. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.