Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to hide your source code?

Reply
Thread Tools

How to hide your source code?

 
 
Immortal Nephi
Guest
Posts: n/a
 
      08-10-2009
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;
}
 
Reply With Quote
 
 
 
 
Marcel Müller
Guest
Posts: n/a
 
      08-10-2009
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;
> }

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Open Source Innovation--Your Computer In Your Pocket Lawrence D'Oliveiro NZ Computing 0 10-28-2005 07:46 AM
ZoneAlarm has detected a problem with your installation, and therefore has restricted Internet access from your machine for your protection. Don’t panic A Teuchter Computer Support 2 05-19-2005 09:20 PM
[HIDE LAN] Hide a part of hosts into the LAN at VPN users? Paolo Bresi Cisco 1 04-04-2005 02:41 PM
hide my source code/ ross HTML 17 06-28-2003 08:35 PM



Advertisments