0

I noticed that declaring an instance of a class with an explicit () does not throw an error despite having deleted the default constructor, why is this?

class Foo {
public:
    Foo() = delete;
};

int main() {
    //Foo foo; // Throws an error as expected
    Foo bar(); // Does not throw an error
    return 0;
}

Compilation invocation: g++ -std=c++14 foo.cpp

asimes
  • 5,749
  • 5
  • 39
  • 76

1 Answers1

2

Unfortunately, Foo bar() is a declaration of function, which returns Foo and takes no arguments.

See Most vexing parse

songyuanyao
  • 169,198
  • 16
  • 310
  • 405