gwaldron / osgearth

3D Maps for OpenSceneGraph / C++14
https://www.pelicanmapping.com/home-1/opensource
Other
1.48k stars 774 forks source link

Compile Error (C++11 only) #2441

Closed cbrl closed 6 months ago

cbrl commented 7 months ago

Describe the bug The following only applies when compiling with the C++11 standard. The requirements causing this error were relaxed in C++14.

The osgEarth::Util::EventRouter::Action struct has members which use in-class initialization.

template<typename FUNC_TYPE>
struct Action {
    FUNC_TYPE func;
    bool eat = true;
};

Because of this, it isn't an aggregate and can't be used with struct initialization as it is in the various EventRouter functions: https://github.com/gwaldron/osgearth/blob/7b8926bfcce486d1d77f0288e206637dd45e22bc/src/osgEarth/ExampleResources#L225

Action requires a user-defined constructor accepting those parameters for the brace initialization to compile. MSVC probably allows this behavior, but GCC will throw errors.

error: no matching function for call to ‘osgEarth::Util::EventRouter::Action<std::function<void()> >::Action(<brace-enclosed initializer list>)’
  225 |             _keypress_simple[key].emplace_back(Action<Function>{ func, eat });
      |                                                                            ^