BobAlmond
BobAlmond

Reputation: 459

how to distinguish function names in C++ if I have same function name but one is C++ and another is C

suppose I have a class with one of the method member name is close, and inside the class, I'm using C function to open and close file

thus, I will have two completely different function with the same name, but one is C and another is C++.

Thus, when I call close, seems compiler is confused

    s = socket(PF_INET, SOCK_DGRAM, 0);
    close(s)

how to solve this issue? Thanks

Upvotes: 1

Views: 517

Answers (3)

Prasad Shinde
Prasad Shinde

Reputation: 662

the compiler usually change the name of functions you define to some unique function name. so if you use function overriding the compiler has its unique name for every function. This is done with the help of name mangling in C++. You should read the concept of name mangling that can help you solve the issue.

Upvotes: 0

Hitesh Vaghani
Hitesh Vaghani

Reputation: 1362

Use scope resolution operator(::) for global function.

Upvotes: 2

Paul Draper
Paul Draper

Reputation: 83205

Your member function:

close(s)

Function in global namespace:

::close(s)

Upvotes: 6

Related Questions