socket and namespace question

E

Ed Fair

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
 
J

John Harrison

Ed Fair said:
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
 
D

David Harmon

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top