C++ compilation error

Can someone explain to me why are the codes below not compilable? I don't understand. Thanks. Revising for a test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Given the following code:
class A {
   int& z;
public:
   A(int z = 0) 
   {
      this->z = z;
   }
};

int main(void) {
  A a();
  return 0;
}
What is the result of compilation?   Success ✘   Warning    Undefined    Error
Last edited on
It will be a compiler error. A reference needs to be associate with an object at initialization time.
Topic archived. No new replies allowed.