Question OOP-CTOR-0063
HardWhat is the output of this code?
#include <iostream>
using namespace std;
class R {
int id;
public:
R(int i) : id(i) { cout << "+" << id; }
~R() { cout << "-" << id; }
};
R g(1);
int main() {
R a(2);
static R s(3);
R b(4);
}
- A.
+1+2+3+4-4-2-3-1
- B.
+1+2+3+4-1-2-3-4
- C.
Sign up free to see the answer and a step-by-step explanation.