 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ed Fair Guest
|
Posted: Thu Mar 04, 2004 6:04 pm Post subject: socket and namespace question |
|
|
Hi,
I am having a name collision between a library call and a class I've
created.
My class is called "socket", it abstracts a TCP socket.
In my constructors for my class, I am calling the socket library function
socket():
m_mySocket = socket(AF_INET,SOCK_STREAM,0)
My compiler is compaining "no overloaded function takes 3 parameters" while
clearly the socket library function does.
Is there a standard way to steer the compiler towards the correct function?
TIA,
ed
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Thu Mar 04, 2004 6:14 pm Post subject: Re: socket and namespace question |
|
|
"Ed Fair" <ed_fair (AT) mindspring (DOT) com> wrote
| Quote: | Hi,
I am having a name collision between a library call and a class I've
created.
My class is called "socket", it abstracts a TCP socket.
In my constructors for my class, I am calling the socket library function
socket():
m_mySocket = socket(AF_INET,SOCK_STREAM,0)
My compiler is compaining "no overloaded function takes 3 parameters"
while
clearly the socket library function does.
Is there a standard way to steer the compiler towards the correct
function?
TIA,
|
I would suggest that you follow the common convention for application code
and capitalise your class names, i.e. Socket. But if you don't want to do
that then you could use a namespace.
namespace networking
{
class socket
{
socket()
{
::socket(AF_INET,SOCK_STREAM,0);
}
};
}
The use of :: indicates that you want the socket library function, which is
in the global namespace, not your socket class (whose full name is
networking::socket).
john
|
|
| Back to top |
|
 |
David Harmon Guest
|
Posted: Thu Mar 04, 2004 6:16 pm Post subject: Re: socket and namespace question |
|
|
On Thu, 04 Mar 2004 18:04:09 GMT in comp.lang.c++, "Ed Fair"
<ed_fair (AT) mindspring (DOT) com> was alleged to have written:
| Quote: | My class is called "socket", it abstracts a TCP socket.
In my constructors for my class, I am calling the socket library function
socket():
m_mySocket = socket(AF_INET,SOCK_STREAM,0)
My compiler is compaining "no overloaded function takes 3 parameters" while
|
m_mySocket = ::socket(AF_INET,SOCK_STREAM,0)
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|