This is the class base question.

Asked 1 years ago, Updated 1 years ago, 248 views

class calculator
{
    private:
               int nsum;
        int nmin;
        int nmul;
        int ndiv;
    public:
        void init(void);
        void show(void);
};

void calculator::init(void) {
     int nsum = 0; 
     int nmin = 0;
     int nmul = 0;
     int ndiv = 0;
}

I think it's very basic.In the definition of the init function, if four variables are declared as int as shown above, Can you tell me in detail why it's because the price of garbage is coming out?


2022-10-18 09:01

1 Answers

void calculator::init(void) {
     int nsum = 0; 
     int nmin = 0;
     int nmul = 0;
     int ndiv = 0;
}

In the function above, intnmin is the region variable of the init function. It does not represent the nmin variable, which is a variable within the calculator class.

What I originally wanted to do is as follows.

void calculator::init(void) {
     nsum = 0; 
     nmin = 0;
     nmul = 0;
     ndiv = 0;
}


2022-10-18 09:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.