Can we prevent function overloading?

Hi,
one of my friend ask me simple question but did not have answer.
can be prevent doing function overloading in c++?
closed account (1yR4jE8b)
1
2
3
4
5
6
7
8
9
10
11
extern "C"
{
    void Function1( char a, char  b );
    void Function1( double b );
}

int main()
{
  
  return 0;
}


$ g++ test.cc
test.cc:4: error: declaration of C function ‘void Function1(double)’ conflicts with
test.cc:3: error: previous declaration ‘void Function1(char, char)’ here
Why would you want to prevent function overloading?
@darkestfright
1
2
3
4
5
6
7
8
9
10
11
12
13
extern "C"
{
    void Function1( char a, char  b );
//    void Function1( double b ); //C doesn't allow it
}

void Function1( double b ); //then I just overload it outside

int main()
{
  
  return 0;
}
Well, you can cheat by creating a variable with a function-type (as seen here:
http://stackoverflow.com/questions/1429547/how-to-prevent-overloading
), but the better question is:

Why would you want to do this?

Function overloading is a Good Thing. Perhaps there is a better solution to the problem you are having.
closed account (1yR4jE8b)
haha, foiled AGAIN!

seriously though, I never even thought about doing this before and a 2 second google search give me that so I posted it.

Nice one though, thanks.
Topic archived. No new replies allowed.