By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,842 Members | 2,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,842 IT Pros & Developers. It's quick & easy.

socket and namespace question

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Ed Fair" <ed*****@mindspring.com> wrote in message
news:tc*******************@newsread1.news.atl.eart hlink.net...
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
Jul 22 '05 #2

P: n/a
On Thu, 04 Mar 2004 18:04:09 GMT in comp.lang.c++, "Ed Fair"
<ed*****@mindspring.com> was alleged to have written:
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)

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.