I'm trying to create a derived class and I am receiving this syntax error for each constructor.
There is no argument given that corresponds to the required formal parameter 'p' of 'Parent.Parent(Parent)'
This doesn't make any sense to me. This is a constructor definition not a method call I have never see this before on something that isn't a call.
namespace ConsoleApp1
{
public class Parent
{
public string Label;
public Parent(Parent p)
{
Label = p.Label;
}
}
public class Child : Parent
{
public string Label2;
public Child(Parent p)
{
Label = p.Label;
}
public Child(Child c)
{
Label = c.Label;
Label2 = c.Label2;
}
public Child(string blah, string blah2)
{
Label = blah;
}
}
class Program
{
static void Main(string[] args)
{
}
}
}
This:
public LabelImage(LabelImage source)
{
Label = source.Label;
image = new MagickImage(source.image);
fileinfo = source.fileinfo;
}
Is implicitly this:
public LabelImage(LabelImage source) : base()
{
Label = source.Label;
image = new MagickImage(source.image);
fileinfo = source.fileinfo;
}
Note the base()
part, trying to call either a MyImageAndStuff
parameterless constructor, or one which only has a params
array parameter, or one with only optional parameters. No such constructor exists, hence the error.
You probably want:
public LabelImage(LabelImage source) : base(source)
{
Label = source.Label;
image = new MagickImage(source.image);
fileinfo = source.fileinfo;
}
... and similar things for all your other constructors. Either that, or you need to add a parameterless constructor to MyImageAndStuff
. It does seem very odd that you can't create an instance of MyImageAndStuff
without already having an instance of MyImageAndStuff
- although I guess source
could be null.
See more on this question at Stackoverflow