avoid function overloading

R

Rahul

Hi Everyone,

I have a function defined in a source file,


sample.cpp

int doit()
{
cout<<"in doit function"<<endl;
}

Now i need to make sure that this function is not overloaded by other
developers, is there anyway to ensure the same?
 
A

Andrey Tarasevich

Rahul said:
I have a function defined in a source file,


sample.cpp

int doit()
{
cout<<"in doit function"<<endl;
}

Now i need to make sure that this function is not overloaded by other
developers, is there anyway to ensure the same?

No, there's no way to ensure anything like that.

Although it is not immediately clear what you mean by "this function". Function
'doit(void)' cannot be "overloaded" from what you defined it to be. Function
'doit' with a different set of parameters can be.
 
R

Rahul

No, there's no way to ensure anything like that.

Although it is not immediately clear what you mean by "this function". Function
'doit(void)' cannot be "overloaded" from what you defined it to be. Function
'doit' with a different set of parameters can be.

Yes, i meant, i don't want any other developer to have the same
function name with different set of arguements...
 
C

ciccio

Rahul said:
Hi Everyone,

I have a function defined in a source file,


sample.cpp

int doit()
{
cout<<"in doit function"<<endl;
}

You have to see function overloading a bit like using identical function
names with different argument list. there is more to it, but this could
be the crude idea. So can somebody overload
int doit();

The answer is no

but he can overload
output doit(with_this);

Obviously a developer can always overload int doit() by directly
altering your code, or if you don't give him your code, he can just kick
it out of the library and incorporate his own.
 
C

ciccio

Yes, i meant, i don't want any other developer to have the same
function name with different set of arguements...

Then I think you would need to create all those functions yourself with
bogus and incorporate them in a library.
 
M

Matt Havener

Why?

Brian

I think there is a symbol table option that errors on a collision. I
had a similar issue with 3rd party libraries and some global symbols.
To avoid this problem entirely, use namespaces, scope everything as
tiny as possible, and prepend names (if you're using pure C). E.g.,
MySection::doit() or MySection_doit().
 
R

Rahul

Hi Everyone,

I have a function defined in a source file,

sample.cpp

int doit()
{
cout<<"in doit function"<<endl;

}

Now i need to make sure that this function is not overloaded by other
developers, is there anyway to ensure the same?

extern "C"
{
#include <sample.h>
}

I would have the prototype of my function in the header file. I would
expect other developers to put in their prototypes too in the header
file as and when they include their overloaded function's prototype in
the header file, g++ compiler would give a compilation error...
 
I

Ian Collins

Rahul said:
extern "C"
{
#include <sample.h>
}

I would have the prototype of my function in the header file. I would
expect other developers to put in their prototypes too in the header
file as and when they include their overloaded function's prototype in
the header file, g++ compiler would give a compilation error...
Put the (conditionally compiled for C++) extern "C" wrapper in the header.
 
A

Andrey Tarasevich

Rahul said:
...
extern "C"
{
#include <sample.h>
}

I would have the prototype of my function in the header file. I would
expect other developers to put in their prototypes too in the header
file as and when they include their overloaded function's prototype in
the header file, g++ compiler would give a compilation error...
...

So, what you said above, is it a part of the original question or the answer to
the original question?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top