Solved

now it is showing two errors.

Posted on 2008-09-30
3
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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