Sub-Classing problem

  • Thread starter Thread starter vnb
  • Start date Start date
V

vnb

when i Build the following sub-class of Socket i get the following error
message

No overload for method 'Socket' takes 0 arguments

can someone tell me how to overcome this problem


using System;
using System.Net.Sockets;

namespace NetClient
{
public class ConnectionSocket : Socket
{
public ConnectionSocket(AddressFamily af, SocketType st, ProtocolType pt)
{
}
}
}
 
vnb,

When you subclass another class, if you do not explictly call the base
constructor when calling your constructor, a call is implied to the
constructor on the base class which takes zero arguments. However, because
the Socket only has one constructor that takes three arguments, this isn't
possible. So, what you need to do is this:

public class ConnectionSocket : Socket
{
public ConnectionSocket(AddressFamily af, SocketType st, ProtocolType
pt) :
base(af, st, pt)
{
}
}

This causes the base constructor to be called correctly.

Hope this helps.
 
Hi, vnb

By default compiler tries to use default base constructor - in this case
base(), and this causes problem.
You have to specify:
public ConnectionSocket(AddressFamily af, SocketType st, ProtocolType
pt)
: base(af,st,pt)

HTH
Alex
 

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

Back
Top