This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,583 Users
  • 2,269,776 Discussions


Cannot initialize object with {} in classes with explicit constructor

koval Member Posts: 72 Blue Ribbon

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.


This discussion has been closed.