ar********@yahoo.co.in wrote:
Hi all,
I have a situation something like this
Class A
{
private data
......
public functions
f1();
f2();
f3();
}
There is another application which uses this class
Class B
{
#include a.h
A objofA;
........
........
}
If I make any changes to the implementation of class A, I need to
recompile the class B. How do I ensure that even if I do any changes to
class A, I don't need to recompile class B. If there any facility
provided by C++ for that?
Yes, it has a strange name. It's called the pimpl idiom (pimpl strands
for pointer to implementation, who makes this up?).
The idea is to use a pointer to the A object in your B class. Now there
are lots of reasons not to do this, it's less efficient and it makes
coding the B class more complex, but if your overriding concern is to
avoid recompilation then it works.
Like this
class A; // forward declaration
class B
{
A* ptrofA;
};
By using a forward declaration of class A you avoid having to #include
"a.h" in b.h, so there is no recompilation when a.h changes.
john