![]() |
How to hide your source code?
How can you hide your implementation source code? You do not want
other programmers to know your source code, but they can only include interface header. They do not require to know private_foo function. They only need to use public_foo function when they are ready to link it to private_foo function’s object code. Is my example below correct? Please comment your suggestion. The class keyword can be used in the implementation source code. How do you say protected or private keyword are not necessary? // Implemenation.h int private_foo( int x, int y ); // Implemenation.cpp #include "impemenation.h" int private_foo( int x, int y ) { int z; for( int a = 0; a < 10; a++ ) z += ( x * y ); return z; } // Interface.h #include "impemenation.h" int public_foo( int x , y ) { return private_foo( x , y ); } // main.cpp #include "interface.h" int main() { int x = 5; int y = 10; int z; z = public_foo( x , y ); return 0; } |
Re: How to hide your source code?
Hi!
Immortal Nephi wrote: > Is my example below correct? The proxy function public_foo is superfluous. The header file is by definition the public part. While the .cpp file is private. See below. > The > class keyword can be used in the implementation source code. How do > you say protected or private keyword are not necessary? Your example does not use any classes. In case of classes the things become a bit more complicated because you have to place at least the class declaration in the public header file. Search for "PIMPL" (Private IMPLementation idiom) and you will find lots of information. Marcel > // Implemenation.h int foo( int x, int y ); > > > // Implemenation.cpp > #include "implemenation.h" int foo( int x, int y ) > { > int z; > > for( int a = 0; a < 10; a++ ) > z += ( x * y ); > > return z; > } > // main.cpp #include "implementation.h" > > int main() > { > int x = 5; > int y = 10; > int z; > > z = public_foo( x , y ); > > return 0; > } |
| All times are GMT. The time now is 06:56 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.