C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

socket and namespace question

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Ed Fair
Guest





PostPosted: Thu Mar 04, 2004 6:04 pm    Post subject: socket and namespace question Reply with 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,

ed


Back to top
John Harrison
Guest





PostPosted: Thu Mar 04, 2004 6:14 pm    Post subject: Re: socket and namespace question Reply with quote




"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





PostPosted: Thu Mar 04, 2004 6:16 pm    Post subject: Re: socket and namespace question Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.