CMyClass::CMyClass()
{
// Some initialization codes
}
int CMyClass::MyFun(int a, int b)
{
// Implemenation of MyFun
}
Now I want to let another developer to use CMyClass, but only want him to be able to:
1. Construct a CMyClass object.
2. Call MyFun function.
and PREVENT him to:
1. Know the implementation of the CMyClass object.
2. Know the existance of the member variable m_iData and m_bFlag.
Now I can put MyClass.h and MyClass.cpp in a static library and compile it, then send the compiled static library as well as only the MyClass.h to the developer, but he will still able to know the protected memory variables m_iData and m_bFlag, and based on them, he can guess the implementation of the MyFun. How to prevent this?
class CMyClass
{
public:
CMyClass();
int MyFun(int a, int b);
protected:
struct Data *m_D;
};
In MyClass.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
struct Data
{
int m_iData;
BOOL m_bFlag;
};
CMyClass::CMyClass() : m_D(new Data)
{
// Some initialization codes
}
int CMyClass::MyFun(int a, int b)
{
// Implemenation of MyFun
}
That's the first time I've seen a forward declaration like that. I was going with the assumption that the OP couldn't compile the code (a comment that's been edited out).