I’m getting ‘Order’ does not contain a constructor that takes 0 arguments. So based on that error, I know it’s in my public class Order. What am I overlooking? Thanks!
public class Order
{
public int QuantityOrdered { get; set; }
public double TotalPrice;
public const double PRICEEACH = 19.95;
virtual public double totalPrice
{
set
{
TotalPrice = QuantityOrdered * PRICEEACH;
}
}
}
public class ShippedOrder : Order
{
public const double SHIPPINGFEE = 4.00;
public override double totalPrice
{
set
{
totalPrice = base.TotalPrice + SHIPPINGFEE;
}
}
}
There has to be a constructor in the Order class you haven’t listed in the code you provided.
When you do not define any constructors for a class, you’re given an implicit parameterless constructor by the compiler.
However, when you add a constructor that takes a parameter, ex.
public Order(string someString) {}, you lose this implicit constructor.What you need to do is one of the following:
Add an explicit parameterless constructor, ex.
public Order() {}Update the code that’s instantiating the Order object to pass the parameter it’s looking for, ex.
new Order(someString)Remove the constructor(s) from Order that expect parameters.