0
class A{
   public:
      A(){cout<<"Constructor called"<<endl;}

      ~A(){cout<<"Destructor called"<<endl;} 
};

int main(int argc, char const *argv[])
{
    A x;
    A y();
    return 0;
}

what is the difference between x and y as x prints while y doesn't print'

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
Mina Samy
  • 3
  • 1
  • 1
    `A y();` -- So how do you declare a function called `y` that takes no parameters and returns an `A` object? See the ambiguity? – PaulMcKenzie Nov 28 '20 at 18:26

1 Answers1

3
A x;

This is declaration of a variable.

A y();

This is declaration of a function.

eerorika
  • 232,697
  • 12
  • 197
  • 326