C++
#include <stdio.h>
class a
{
public:
int var1;
a(int var)
{
var1 = var;
printf("set var1 to %d\n", var1);
}
};
class b: public a
{
public:
int var2;
b(int d) : var2(d++), a(var2++)
{
printf("d: %d, var2: %d, var1: %d\n", d, var2, var1);
}
};
int main()
{
int a = 5;
b obj1(a);
printf("%d\n", obj1.var1);
}
Output:
set var1 to 0
d: 6, var2: 5, var1: 0
0
[Finished in 0.7s]
Why is a.var1 not set to 6 here?
aas an int variable when you also have a public class namedaobscures the code a bit, although isn't the cause of your problem.