#include<iostream>
using namespace std;
class Alpha
{
int a;
public:
void get_a(int x)
{
a = x;
}
int hello()
{
return a;
}
};
class Beta : public Alpha
{
int b, c;
public:
void get_b(int y)
{
b = y;
}
void add()
{
c = hello() + b;
cout << c << endl; // displays garbage value
}
};
int main()
{
Alpha v1;
Beta v2;
v1.get_a(4);
v2.get_b(3);
v2.add();
v2.disp();
return 0;
}
The output of v2.disp() shows garbage value but when I initalise "a" as v2.get_a instead of v1.get_a , it shows the correct answer. New to C++ btw. Please help. Thanks.