default constructor for weak_wnd

2005-01-11
2013-04-15
  • Steven Weiss

    Steven Weiss - 2005-01-11

    hi john,
    i wrote an event_handler and wondered about the following compiler output:

    error C2512: 'assistant::dialog1_handler' : no appropriate default constructor available
            j:\Projekte\win32gui\win32gui\event_handler.hpp(54) : while compiling class-template member function 'win32::gui::detail::event_handler_bottom<base>::event_handler_bottom(win32::gui::window_base *)'
            with
            [
                base=assistant::dialog1_handler
            ]
            j:\Projekte\win32gui\win32gui\detail\event_handling\wnd_relation.hpp(127) : see reference to class template instantiation 'win32::gui::detail::event_handler_bottom<base>' being compiled
            with
            [
                base=assistant::dialog1_handler
            ]
            j:\Projekte\win32gui\win32gui\detail\event_handling\wnd_relation.hpp(127) : while compiling class-template member function 'win32::gui::detail::event_handler_base *win32::gui::detail::event_handler_creator_impl<self,base,derived,evt_type>::create(win32::gui::window_base *)'
            with
            [
                self=assistant::dialog1_handler,
                base=win32::gui::detail::event_handler_creator<assistant::dialog1_handler,assistant::dialog1,win32::gui::all_base_classes,events_after>::base,
                derived=win32::gui::detail::event_handler_creator<assistant::dialog1_handler,assistant::dialog1,win32::gui::all_base_classes,events_after>::derived,
                evt_type=events_after
            ]
            j:\Projekte\win32gui\win32gui\detail\event_handling\wnd_relation.hpp(165) : see reference to class template instantiation 'win32::gui::detail::event_handler_creator_impl<self,base,derived,evt_type>' being compiled
            with
            [
                self=assistant::dialog1_handler,
                base=win32::gui::detail::event_handler_creator<assistant::dialog1_handler,assistant::dialog1,win32::gui::all_base_classes,events_after>::base,
                derived=win32::gui::detail::event_handler_creator<assistant::dialog1_handler,assistant::dialog1,win32::gui::all_base_classes,events_after>::derived,
                evt_type=events_after
            ]
            j:\Projekte\win32gui\win32gui\event_handler.hpp(367) : see reference to class template instantiation 'win32::gui::detail::event_handler_creator<self,base_or_derived,derived_type,evt_type>' being compiled
            with
            [
                self=assistant::dialog1_handler,
                base_or_derived=assistant::dialog1,
                derived_type=win32::gui::all_base_classes,
                evt_type=events_after
            ]
            j:\Projekte\win32gui_assistant\win32gui_assistant\dialog1.cpp(30) : see reference to class template instantiation 'win32::gui::event_handler<self_type,base_or_derived>' being compiled
            with
            [
                self_type=assistant::dialog1_handler,
                base_or_derived=assistant::dialog1
            ]

    it turned out that the cause of this compiler error is a weak_wnd-member of my handler. because weak_wnd has NO default constructor it is necessary to write explicitely a default constructor for the event_handler:

    struct dialog1_handler : event_handler<dialog1_handler, dialog1>
    {
    private:
        weak_wnd<tree_ctrl> tree_;

    public:
        dialog1_handler() : tree_(win32::gui::detail::null_wnd_t())
        {}
    ...
    };

    did you intend this (there's no note in the source)? i think it would be nicer if weak_wnd has a default constructor. it would not be more dangerous because if you aren't sure if the weak_wnd is valid you would have to test it anyway

    mfg steven

     
    • John Torjo

      John Torjo - 2005-01-12

      Yup, you're right.
      It's on my TODO list ;)

      As a side-note, you should say:
      tree_(win32::gui::detail::null_wnd)
      instead of
      tree_(win32::gui::detail::null_wnd_t())

      (it's shorter:))

      Best,
      John

       

Log in to post a comment.