473,409 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Ask about iherite

i want to inherit class Socket in System.Nets.Sockets, but when i use this code:

public class NewSocket : System.Net.Sockets.Socket{
public NewSocket(){
}
}

and when i build it warning : No overload for method 'Socket' takes '0' arguments. Anyone please help me. Can U show me the way to inherit Socket class because request of my project is rewrite Socket with some new function. Thanks alot!
Nov 16 '05 #1
6 2372
The signature of the public Socket..ctor is:
public Socket(AddressFamily addressFamily, SocketType socketType,
ProtocolType protocolType)

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Nguyen Thanh Danh" <k6*****@hcmc.netnam.vn> wrote in message
news:ec******************@TK2MSFTNGP12.phx.gbl...
i want to inherit class Socket in System.Nets.Sockets, but when i use this
code:

public class NewSocket : System.Net.Sockets.Socket{
public NewSocket(){
}
}

and when i build it warning : No overload for method 'Socket' takes '0'
arguments. Anyone please help me. Can U show me the way to inherit Socket
class because request of my project is rewrite Socket with some new
function. Thanks alot!
Nov 16 '05 #2


"Nguyen Thanh Danh" wrote:
i want to inherit class Socket in System.Nets.Sockets, but when i use this code:

public class NewSocket : System.Net.Sockets.Socket{
public NewSocket(){
}
}

and when i build it warning : No overload for method 'Socket' takes '0' arguments. Anyone please help me. Can U show me the way to inherit Socket class because request of my project is rewrite Socket with some new function. Thanks alot!


You have to call the superclass constructor is what I think the other guy is
getting at. The way you have it written the compiler is trying to find a
default constructor for the Socket class. 'No constructor for socket takes 0
arguments' so your constructor cannot construct the base class. The syntax
escapes me right now (auto completion makes you so lazy!) but in Java you
would do

public MySocket
{
super(addressFamily, socketType, protocolType);
...

in C++ I think it was

public NewSocket() : Socket(addressFamily, socketType, protocolType)
{
...

You can pass the arguments from your constructor to the base class
constructor. I can't believe I can't remember the syntax, but hopefully I
have put you on the right track and someone will come along shortly to close
the thread. :-)

Aaron.
Nov 16 '05 #3
Aaron Oxford wrote:
"Nguyen Thanh Danh" wrote:
i want to inherit class Socket in System.Nets.Sockets, but when i
use this code:

public class NewSocket : System.Net.Sockets.Socket{
public NewSocket(){
}
}

and when i build it warning : No overload for method 'Socket' takes
'0' arguments. Anyone please help me. Can U show me the way to
inherit Socket class because request of my project is rewrite Socket
with some new function. Thanks alot!


You have to call the superclass constructor is what I think the other
guy is getting at. The way you have it written the compiler is trying
to find a default constructor for the Socket class. 'No constructor
for socket takes 0 arguments' so your constructor cannot construct
the base class. The syntax escapes me right now (auto completion
makes you so lazy!) but in Java you would do

public MySocket
{
super(addressFamily, socketType, protocolType);
...

in C++ I think it was

public NewSocket() : Socket(addressFamily, socketType, protocolType)
{
...

You can pass the arguments from your constructor to the base class
constructor. I can't believe I can't remember the syntax, but
hopefully I have put you on the right track and someone will come
along shortly to close the thread. :-)

Aaron.


in C# :

public MySocket(<params>): base(addressFamily, socketType, protocolType)
{
}

... which is a problem if you want to *calculate* the values to be passed,
instead of just passing the parameters to your own constructor + constants.
Possibly you can use functions here to calculate the values you really want.

Hans Kesting
Nov 16 '05 #4
thanks all of u, but i can't do it myselt, i try all way like u said but it
still warning(another warning). Can u give me a code that can inherit class
Socket without nay warning?

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:Ou**************@TK2MSFTNGP15.phx.gbl...
Aaron Oxford wrote:
"Nguyen Thanh Danh" wrote:
i want to inherit class Socket in System.Nets.Sockets, but when i
use this code:

public class NewSocket : System.Net.Sockets.Socket{
public NewSocket(){
}
}

and when i build it warning : No overload for method 'Socket' takes
'0' arguments. Anyone please help me. Can U show me the way to
inherit Socket class because request of my project is rewrite Socket
with some new function. Thanks alot!
You have to call the superclass constructor is what I think the other
guy is getting at. The way you have it written the compiler is trying
to find a default constructor for the Socket class. 'No constructor
for socket takes 0 arguments' so your constructor cannot construct
the base class. The syntax escapes me right now (auto completion
makes you so lazy!) but in Java you would do

public MySocket
{
super(addressFamily, socketType, protocolType);
...

in C++ I think it was

public NewSocket() : Socket(addressFamily, socketType, protocolType)
{
...

You can pass the arguments from your constructor to the base class
constructor. I can't believe I can't remember the syntax, but
hopefully I have put you on the right track and someone will come
along shortly to close the thread. :-)

Aaron.


in C# :

public MySocket(<params>): base(addressFamily, socketType, protocolType)
{
}

.. which is a problem if you want to *calculate* the values to be passed,
instead of just passing the parameters to your own constructor +

constants. Possibly you can use functions here to calculate the values you really want.
Hans Kesting

Nov 16 '05 #5
> "Nguyen Thanh Danh" wrote:
i want to inherit class Socket in System.Nets.Sockets,
but when i use this code:

public class NewSocket : System.Net.Sockets.Socket{
public NewSocket(){
}
}

and when i build it warning : No overload for method
'Socket' takes '0' arguments. Anyone please help me.
Can U show me the way to inherit Socket class because
request of my project is rewrite Socket
with some new function. Thanks alot!


To achieve what you want, you have to provide more information, such as what
the Socket is supposed to be used for.

When you inherit from Socket, you have to call the constructor of the
super-class with valid arguments. There is a large list of constants you can
use there, but which ones to use is depending on what you'll be using it
for.

One simple example that compiles without warnings:

using System.Net.Sockets;

public class MySocket : Socket
{
public MySocket( ) :
base(
AddressFamily.InterNetwork,
SocketType.Unknown,
ProtocolType.Tcp)
{
}
}

I suggest you look into the different constants of AddressFamily, SocketType
and ProtocolType, to decide which ones are best suited for your project.

If it's just added functionality you're after, you don't have to use the
*empty* constructor at all. To create an instance of Socket you have to
provide three arguments, whick you can do with the sub-class as well. This
example will also work:

using System.Net.Sockets;

public class MySocket : Socket
{
public MySocket(
AddressFamily a,
SocketType s,
ProtocolType p ) : base(a, s, p)
{
}
}

// Bjorn A

Nov 16 '05 #6
Thanks for ur help!

"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP10.phx.gbl...
"Nguyen Thanh Danh" wrote:
i want to inherit class Socket in System.Nets.Sockets,
but when i use this code:

public class NewSocket : System.Net.Sockets.Socket{
public NewSocket(){
}
}

and when i build it warning : No overload for method
'Socket' takes '0' arguments. Anyone please help me.
Can U show me the way to inherit Socket class because
request of my project is rewrite Socket
with some new function. Thanks alot!

To achieve what you want, you have to provide more information, such as

what the Socket is supposed to be used for.

When you inherit from Socket, you have to call the constructor of the
super-class with valid arguments. There is a large list of constants you can use there, but which ones to use is depending on what you'll be using it
for.

One simple example that compiles without warnings:

using System.Net.Sockets;

public class MySocket : Socket
{
public MySocket( ) :
base(
AddressFamily.InterNetwork,
SocketType.Unknown,
ProtocolType.Tcp)
{
}
}

I suggest you look into the different constants of AddressFamily, SocketType and ProtocolType, to decide which ones are best suited for your project.

If it's just added functionality you're after, you don't have to use the
*empty* constructor at all. To create an instance of Socket you have to
provide three arguments, whick you can do with the sub-class as well. This
example will also work:

using System.Net.Sockets;

public class MySocket : Socket
{
public MySocket(
AddressFamily a,
SocketType s,
ProtocolType p ) : base(a, s, p)
{
}
}

// Bjorn A

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.