sark9012
sark9012

Reputation: 5747

expected class,delegate,enum,interface or struct

I am writing a class. I have encountered the problem in the title. Here is the code:

class delivery
{
    private string strDeliveryName;
    private string strDeliveryAddress;
    private string strDeliveryDay;
    private string strDeliveryTime;
    private string strDeliveryMeal;
    private string strDeliveryInstructions;
    private string strDeliveryStatus;
}
public delivery(string deliveryName, string deliveryAddress, string deliveryDay, string deliveryTime, string deliveryMeal, string deliveryInstructions, string deliveryStatus)
    {
        strDeliveryName = deliveryName;
        strDeliveryAddress = deliveryAddress;
        strDeliveryDay = deliveryDay;
        strDeliveryTime = deliveryTime;
        strDeliveryMeal = deliveryMeal;
        strDeliveryInstructions = deliveryInstructions;
        strDeliveryStatus = deliveryStatus;
    }

I get the error on the public delivery, any idea why?

Upvotes: 2

Views: 11698

Answers (5)

c0bra
c0bra

Reputation: 3012

I received this error because I accidentally missed an open brace in code above where the error occurred. This meant the class ended prematurely. So if you get this error maybe check that your braces are correct.

Upvotes: 0

Jayasankar.K
Jayasankar.K

Reputation: 11

This error is because you have declared the function outside of the main class. You should insert your code inside the main class.

Upvotes: 1

SLaks
SLaks

Reputation: 887757

To answer your second question (in the comment), you need to change the name of the constructor to match the name of the class.

Upvotes: 2

Enigmativity
Enigmativity

Reputation: 117104

Your constructor code is not inside the class. Move it inside and all should be fine. :-)

Upvotes: 2

unholysampler
unholysampler

Reputation: 17331

Your constructor should be within the brackets of the class definition. On an unrelated note, the convention is to capitalize the first letter of class names.

Upvotes: 14

Related Questions