Skip to Main Content

DevOps, CI/CD and Automation

Cannot initialize object with {} in classes with explicit constructor

kovalAug 1 2017 — edited Aug 2 2017

Both Studio 12.5 and 12.6 give error on {} initialization of objects for classes with explicit constructor

struct Class {

    explicit Class() { }


Class returning()


    Class c{};

    return c;


Error message:

line 7: Error: Could not find a match for Class::Class({initializer list}) needed in returning()

I find it a bug, explicit constructor should disallow Class object = {}; but not direct default initialization.

When constructor is default (i.e. explicit Class() = default;) the error disappears.

Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2017
Added on Aug 1 2017
1 comment