在 XNA 中使用 C# 调用子构造函数的问题
Problems calling child constructor using C# in XNA
我有两个类,一个继承了另一个。
分区
class Partition
{
protected Vector3 midpoint
protected float radius
public Partition(Vector3 midpoint, float radius)
{
this.midpoint = midpoint;
this.radius = radius;
}
}
分区段
class PartitionSegment : Partition
{
protected Vector3 midpoint
protected float radius
public PartitionSegment(Vector3 midpoint, float radius)
{
this.midpoint = midpoint;
this.radius = radius;
}
}
我在 PartitionSegment 的构造函数中被标记为错误。
PartitionJunction.PartitionJunction(Vector3 midPoint, float radius)
There is no argument given that corresponds to the required parameter 'midPoint' of 'Partition.Partition(Vector3, float)'
我做错了什么?
还记得小时候开发C#,不用写吗? :
public PartitionSegment(Vector3 midpoint, float radius) : base(midpoint, radius)
{ }
您可以使用基础构造函数。
public PartitionSegment(Vector3 midpoint, float radius) : base(midpoint, radius)
{
//additional relevant code
}
为您的分区基础 class 提供一个参数较少的默认构造函数也会消除您的错误消息。
我有两个类,一个继承了另一个。
分区
class Partition
{
protected Vector3 midpoint
protected float radius
public Partition(Vector3 midpoint, float radius)
{
this.midpoint = midpoint;
this.radius = radius;
}
}
分区段
class PartitionSegment : Partition
{
protected Vector3 midpoint
protected float radius
public PartitionSegment(Vector3 midpoint, float radius)
{
this.midpoint = midpoint;
this.radius = radius;
}
}
我在 PartitionSegment 的构造函数中被标记为错误。
PartitionJunction.PartitionJunction(Vector3 midPoint, float radius)
There is no argument given that corresponds to the required parameter 'midPoint' of 'Partition.Partition(Vector3, float)'
我做错了什么?
还记得小时候开发C#,不用写吗? :
public PartitionSegment(Vector3 midpoint, float radius) : base(midpoint, radius)
{ }
您可以使用基础构造函数。
public PartitionSegment(Vector3 midpoint, float radius) : base(midpoint, radius)
{
//additional relevant code
}
为您的分区基础 class 提供一个参数较少的默认构造函数也会消除您的错误消息。