c# multi inheritance

Posted by user326839 on Stack Overflow See other posts from Stack Overflow or by user326839
Published on 2010-04-27T12:28:50Z Indexed on 2010/04/27 12:43 UTC
Read the original article Hit count: 281

Filed under:
|
|
|
|

So ive got a base class which requires a Socket:

    class Sock
{
    public Socket s;

    public Sock(Socket s)
    {
        this.s = s;
    }
    public virtual void Process(byte[] data) { }

... }

then ive got another class. if a new socket gets accepted a new instance of this class will be created:

    class Game : Sock
{
    public Random Random = new Random();

    public Timerr Timers;
    public Test Test;

    public Game(Socket s) : base(s) { }

    public static void ReceiveNewSocket(object s)
    {
        Game Client = new Game((Socket)s);
        Client.Start();
    }
    public override void Process(byte[] buf)
    {
        Timers = new Timerr(s);
        Test = new Test(s);
        Test.T();
    }
}

in the Sock class ive got a virtual function that gets overwritten by the Game class.(Process function) in this function im calling a function from the Test Class(Test+ Timerr Class:

    class Test : Game
{
    public Test(Socket s) : base(s) { }

    public void T()
    {
        Console.WriteLine(Random.Next(0, 10));
        Timers.Start();
    }

}

class Timerr : Game
{
    public Timerr(Socket s) : base(s) { }

    public void Start()
    {
        Console.WriteLine("test");
    }

}

) So in the Process function im calling a function in Test. And in this function(T) i need to call a function from the Timerr Class.But the problem is its always NULL , although the constructor is called in Process. And e.g. the Random Class can be called, i guess its because its defined with the constructor.:

public Random Random = new Random();

and thats why the other classes(without a constructor):

public Timerr Timers;
public Test Test;

are always null in the inherited class Test.But its essentiel that i call other Methods of other classes in this function.How could i solve that?

© Stack Overflow or respective owner

Related posts about c#

Related posts about inheritance