Last Updated on May 3, 2022 by Admin 2
What is the output of the following snippet?
#include <iostream> using namespace std; class X { public: int v; void put(int x) { v =x; } int get(void) { return v; } }; class Y : public X { public: Y() { put(0); } void write(int x) { put(x + 1); } int read(void) { return get() - 1; } }; int main() { Y *y = new Y(); y ->write(1); cout << y->read(); delete y; return 0; }
1
-1
- Compilation fails
0