jeudi 25 mai 2017

Initializer list with struct in vs2015u3

This seems trivial but doesn't work

    namespace Timer {

        struct T
        {
            int milliseconds = 0;
            int cmd_id = 0;
        };

        T init(const HWND hwnd) {
            T t = { 0, 0 } ;
            return t;
        }
    }

caller

auto timer = Timer::init();

Errors in VS2015u3 with

h:\lfwin32\lfwin32.h(21): error C2440: 'initializing': cannot convert from 'initializer list' to 'LFWin32::Timer::T'
  h:\lfwin32\lfwin32.h(21): note: No constructor could take the source type, or constructor overload resolution was ambiguous

I would have thought this was standard with C++11 onwards. Is there an option I need to set?

Aucun commentaire:

Enregistrer un commentaire