Reputation:
I have two classes declared like this:
class Object1
{
protected ulong guid;
protected uint type;
public Object1(ulong Guid, uint Type)
{
this.guid = Guid;
this.type = Type
}
// other details omitted
}
class Object2 : Object1
{
// details omitted
}
In the client code, I want to be able to create an instance of each object like this:
Object1 MyObject1 = new Object1(123456789, 555);
Object2 MyObject2 = new Object2(987654321, 111);
How can I get Object2 to use Object1's constructor like that? Thankyou.
Upvotes: 3
Views: 3321
Reputation: 29956
Give Object2 a constructor like this:-
public Object2(ulong Guid, uint Type): base(Guid, Type)
Upvotes: 1
Reputation: 32698
You have to provide a constructor with the same signature for Object2 and then call the base class's constructor:
class Object2 : Object1
{
public Object2(ulong Guid, uint Type) : base(Guid, Type) {}
}
Upvotes: 1
Reputation: 56934
class Object2 : Object1
{
Object2(ulong l, uint i ) : base (l, i)
{
}
}
Upvotes: 9