I'm doing C++ tests for my certification exam and I came across this exercise that i don't understand: (the question is what is the output of the following program)
#include <iostream>
using namespace std;
class A {
public :
float v;
float set(float v) {
A::v += 1.0;
A::v = v+1.0;
return v;
}
float get(float v){
v +=A::v;
return v;
}
};
int main()
{
A a;
cout<< a.get(a.set(a.set(0.5)));
return 0;
}
I expected to have an error on the first line of the set function since A::v was never initialized, but my program compiles and it seems that A::v has value 0 by default.. Could someone please explain why there is no compilation error?