October 26th, 2011, 06:28 AM
How to disclose class interface but hide implementation
I want to write a C++ class, like this:
int MyFun(int a, int b);
// 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?
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!