1

There is a class with a non-default constructor.

#include <iostream>

class Foo {

public:

  Foo(int a) { std::cout << "Constructor" << std::endl; };

}

So the default constructor couldn't be invoked:

   Foo obj; // compilation error

The non-default constructor can be inkoved:

   Foo obj(1);

Question:

What happens in the following line that compiles?

   Foo obj(); 
Konstantin
  • 2,937
  • 10
  • 41
  • 58

1 Answers1

4

You create a function prototype with no parameters.

To be more specific... basically nothing happens

Kupto
  • 2,802
  • 2
  • 13
  • 16
  • See also "C Forward Declaration" – awiebe Feb 10 '17 at 06:20
  • 2
    Well something happens, you said that function exists, so you're gonna get strange link-time errors if you accidentally manage to invoke it and haven't provided an implementation. – awiebe Feb 10 '17 at 06:24
  • sure, but during execution nothing happens, no construction, no stack allocation, nottin, the line has no effect – Kupto Feb 10 '17 at 06:26