| | |
Overloaded Functions Problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2008
Posts: 5
Reputation:
Solved Threads: 0
Ok I have this problem which is very simple yet I can't find the solution anywhere.
I have a simple function:
This function does a lot of work and one of the things it needs to do it shutdown and close a socket with socket descriptor being "sockFd"
The problem is with the
call that I make to close the socket and release resources. The problem is that it has the same exact function signature as my function and so what ends up happening is a recursive call to my function rather than a call to the "close()" function to close a socket
I figured I need to somehow differentiate them so I tried using std::close() but close() is not part of that namespace.
So does anyone know where close() is defined so I could do something like "SomeClass::close()"
Oh and by the way I can't just rename my function to something else. Part of my requirements is that my function be called close().
Please if anyone has ideas I would appreciate them.
I have a simple function:
C++ Syntax (Toggle Plain Text)
bool MyClass::close(int fd) { // code shutdown(sockFd, 2); close(sockFd); //code }
This function does a lot of work and one of the things it needs to do it shutdown and close a socket with socket descriptor being "sockFd"
The problem is with the
•
•
•
•
close(sockFd);
I figured I need to somehow differentiate them so I tried using std::close() but close() is not part of that namespace.
So does anyone know where close() is defined so I could do something like "SomeClass::close()"
Oh and by the way I can't just rename my function to something else. Part of my requirements is that my function be called close().
Please if anyone has ideas I would appreciate them.
•
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
You're using the function; presumably you can work out which header it came from. close() is not a standard function in C or C++.
I'm guessing it is a function related to sockets handling under win32 or unix (typically in a header like <io.h>, but that varies). If my guess is correct, it may be unambiguously called using "::close(sockFd);"
If my guess is wrong (eg it's a macro) then your only choice would be to rename your MyClass::close() function .... for example to MyClass::finish().
I'm guessing it is a function related to sockets handling under win32 or unix (typically in a header like <io.h>, but that varies). If my guess is correct, it may be unambiguously called using "::close(sockFd);"
If my guess is wrong (eg it's a macro) then your only choice would be to rename your MyClass::close() function .... for example to MyClass::finish().
•
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
::close() just means the function close() is within the global (unnamed) namespace.
In C++, if a function is not explicitly declared with a namespace, it is placed in the global (unnamed) namespace. That's what happens, by default, with functions from C standard headers (<stdio.h>, etc) and all third-party library functions that can be accessed from C.
If you declare a function at file scope, and don't explicitly place it in a namespace, it will also be within the unnamed global namespace. So, a function declared at file scope.
has a fully qualified name of ::f().
In C++, if a function is not explicitly declared with a namespace, it is placed in the global (unnamed) namespace. That's what happens, by default, with functions from C standard headers (<stdio.h>, etc) and all third-party library functions that can be accessed from C.
If you declare a function at file scope, and don't explicitly place it in a namespace, it will also be within the unnamed global namespace. So, a function declared at file scope.
C++ Syntax (Toggle Plain Text)
void f();
![]() |
Similar Threads
- operator= overloading problem (C++)
- Overloaded Function Help (C++)
- problem with operator overloading (C++)
- Overloading << & >> operators (C++)
- Adding binary values from a file (C++)
- Overloaded Functions C++ (C++)
- overloading problem (C++)
- Need to know hwo to go about this (classes/accessor functions) (C++)
Other Threads in the C++ Forum
- Previous Thread: Help Me Please !!!
- Next Thread: Outputting formatted data to file
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





