Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5995503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:58:08+00:00 2026-05-22T23:58:08+00:00

This is homework…I’m not asking for answers, I just have a bug I’m not

  • 0

This is homework…I’m not asking for answers, I just have a bug I’m not sure what to do with. Thanks!

The bug in question probably has nothing to do with the assignment itself, but here is the assignment description anyways:

I’m working on an assignment (in C++) meant to teach use of the decorator design pattern through the classic example of a pizza with toppings. (My professor may as well have lifted it straight from http://simplestcodings.com/2010/12/26/decorator-design-pattern-example-ni-c/). I’m running into a little problem that I was wondering if someone could help me with.

I have a main menu(pizzeria) object that takes input from the user and performs the desired actions on a pizza. Users start with a basic pizza and then can add toppings to it until they’re done. So the first thing that my “newPizza” function does is declare the new Pizza as a Plain, which is a subclass of abstract class Pizza.

Then they get to enter their choice of toppings. Each time, a pointer to the same Pizza object is sent to the addToppings() function, the new decoration is added, and the pointer is returned. Each decoration inherits from a price category, which inherits from pizzaToppings, which inherits from Pizza.

This is the relevant part of the main order function:

Pizza* Menu::newPizza()
{
cout << "\nNew Pizza";

//accept the next choice
int choose = 0;

//create the new pizza
Plain * currentPizza = new Plain();

//until they choose to end the order
while (choose != 3)
{
    //accept the choice
    cin >> choose;

    switch (choose)
    {
        //if they want to add a new topping
    case 1:
        {
            //add topping to current pizza
           //and this is where the problem is spotted by the compiler
            addTopping(currentPizza);
            break;
        }

The issue is that when I try to send the pointer currentPizza to the function addTopping(), I get
“Run-Time Check Failure #3 – The variable ‘currentPizza’ is being used without being initialized.”

Didn’t I just initialize it right there on line 7?

If I hit “continue”, the program keeps going, and works, but I get that same error every time I call the function. Is it just a syntax error somewhere, or do I have some actual issue here?

Thanks!!

[edit:]

The addTopping() function:

Pizza* Menu::addTopping(Pizza* thisPizza)
{
cout << "\nAdd topping";

//declare choose int
int choose = 0;

//accept number of topping
cin >> choose;

//decide which one to add
switch (choose)
{

//mozzarella
case 1:
    {
        thisPizza = new Mozzarella(thisPizza);
        break;
    }
//mushrooms
case 2:
    {
        thisPizza = new Mushrooms(thisPizza);
        break;
    }

//another 13 possible toppings, won't bore you with the details ;)

}

cout << "\nEnd add topping\n";

return thisPizza;
}
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:58:09+00:00Added an answer on May 22, 2026 at 11:58 pm

    Do you have currentPizza also declared as an field of the Pizza class and you are using that somewhere else? If so, the currentPizza you are updating in newPizza is specific to that method, and you need to do just currentPizza = new Plain(); instead of declaring a new currentPizza variable in the scope of the method.

    Also, in your addTopping method, you are only updating the argument thisPizza, which is a copy of the pointer currentPizza.

    You need to do:

    currentPizza = addTopping(currentPizza);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this homework question: Assume a Database table has 0 records at time
I have this homework to do in C. I'm beginner so it is probably
So I'll admit that this is a homework assignment, but I'm not asking you
This is homework, just so that's mentioned. I have project called AdventCalendar, which is
I'm still not very good with data structures, but I have this homework assignment
I'm not asking for anyone to do this homework for me, but I bring
I have a linked list question that stems from this homework prompt I am
well I'm doing this homework but I'm still not viewing the fault... When I
(Before anyone says anything Yes this was homework but i have already turned it
I have this homework problem where I need to use regex to remove every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.