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

Recommended Answers

All 3 Replies

Do you know about inclusion guards?

// myheader.h
#ifndef MYHEADER_H
#define MYHEADER_H

// Your class here

#endif

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".. :)

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.