Sha*_*yte 1 c# inheritance constructor
我已经谷歌"调用基础构造函数",我没有得到我需要的答案.
这是我的构造函数;
public class defaultObject
{
Vector2 position;
float rotation;
Texture2D texture;
public defaultObject(Vector2 nPos, float nRotation, Texture2D nTexture)
{
position = nPos;
rotation = nRotation;
texture = nTexture;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有了这个,我想继承构造函数及其所有工作.这是我期望做的;
public class Block : defaultObject
{
// variables inherited from defaultObject
public Block : defaultObject; //calls defaultObject constructor
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能这样做?
用途: base()
:
public class Block : defaultObject
{
// variables inherited from defaultObject
public Block ()
: base()
{}
}
Run Code Online (Sandbox Code Playgroud)
或带参数:
public class Block : defaultObject
{
// variables inherited from defaultObject
public Block (Vector2 nPos, float nRotation, Texture2D nTexture)
: base(nPos, nRotation, nTexture)
{}
}
Run Code Online (Sandbox Code Playgroud)