lundi 4 avril 2022

When i overload constructor it doesn't work properly C++ [closed]

class sum
{
    protected:
        int num, rang;
    public:
        sum(){
            cin >> num;
            cin >> rang;
        }
        sum(int num, int rang){
            int n = 10;
            int sum = 0;
            for(int i = 0; i < rang; i++){
                num += n; 
                sum += num;
            }
            num = sum;
            cout << num << '\n';
        }
};

int main()
{
    sum obj;    
    return 0;
}

When I call second costructor (overload constructor), it should print sum, but it prints nothing, I think it even isn't calling by previous censtructor, why?

Aucun commentaire:

Enregistrer un commentaire