Garmaine Staff asked 2 years ago
#include <iostream>

using namespace std;

class calculator {
public:
    int n1, n2;

    friend void setNumbers(calculator v);
    friend void getNumbers(calculator v);
};

void setNumbers(calculator v) {
    cin >> v.n1 >> v.n2;
}

void getNumbers(calculator v) {
    cout << v.n1 << ' ' << v.n2 << '\n';
}

int main() {
    calculator calc;
    setNumbers(calc);
    getNumbers(calc);
    return 0;
}

When I call getNumbers function, it prints totally different values which I didn't input. For example when I input 3 6, it prints 0 1, while I expected 3 6. What could be wrong?