Solved

now it is showing two errors.

Posted on 2008-09-30
3
199 Views
Last Modified: 2012-05-05
1) no overload for method 'FoodItem' takes 0 arguments.
2) Use of keyword base is not valid in this context
0
Comment
Question by:sarang8180
  • 2
3 Comments
 
LVL 5

Expert Comment

by:johnaryan
ID: 22604206
Could you add a snippet of your code.
Perhaps you have not defined a constructor with that accepts 2 parameters

John
0
 
LVL 14

Expert Comment

by:Binuth
ID: 22604211
Are you using same code posted by "oxyoo" ? if not use same code
    /// <summary>
    /// Summary description for FoodItem.
    /// </summary>
    public class FoodItem
    {
        private extern int Calories_Per_Gram = 9;
        private readonly int fatgrams;
        protected int servings;
 
        public FoodItem()
        {
        }
 
        public FoodItem(int Fatgrams1, int servings1)
        {
            fatgrams = Fatgrams1;
            servings = servings1;
        }
 
        private int Calories()
        {
            return fatgrams*Calories_Per_Gram;
        }
 
        public int CaloriesPerSavings()
        {
            return (Calories()/servings);
        }
    }
 
 
 
 
 
 
    /// <summary>
    /// Summary description for Pizza.
    /// </summary>
    public class Pizza : FoodItem
    {
        public Pizza(int fatGrams) : base(fatGrams, 8)
        {
        }
    }

Open in new window

0
 
LVL 5

Accepted Solution

by:
johnaryan earned 500 total points
ID: 22604234
I just tried that and it worked fine.
I used this to call the below:

static void Main(string[] args)
        {
             Pizza p = new Pizza(2);
        }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestConsole
{
    /// <summary>
    /// Summary description for FoodItem.
    /// </summary>
    public class FoodItem
    {
        protected int Calories_Per_Gram = 9;
        private readonly int fatgrams;
        protected int servings;
 
        public FoodItem()
        {
        }
 
        public FoodItem(int Fatgrams1, int servings1)
        {
            fatgrams = Fatgrams1;
            servings = servings1;
        }
 
        private int Calories()
        {
            return fatgrams * Calories_Per_Gram;
        }
 
        public int CaloriesPerSavings()
        {
            return (Calories() / servings);
        }
    }
 
    /// <summary>
    /// Summary description for Pizza.
    /// </summary>
    public class Pizza : FoodItem
    {
        public Pizza(int fatGrams)
            : base(fatGrams, 8)
        {
        }
    }
}

Open in new window

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now