-3

I have a class called "Complex" which is intended to represent complex numbers. I have defined an empty default constructor for the class that only prints a message to the screen. When I try to create an object of the class in the main function as follows:

Complex c1();

The compiler(I am using BorlandC) doesn't give a syntax error but it doesn't create the object. How does the compiler interpret this line?

Islam Hassan
  • 673
  • 1
  • 10
  • 21

1 Answers1

4

When you write this:

int foo();

…it declares a function called foo that returns an int.

When you write this:

Complex c1();

…it declares a function called c1 that returns a Complex.

Lose the ().

Contrary to popular belief, this is not quite "the most vexing parse", but it is close.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055