I created a header for optionally lazy parameters (also visible on GitHub repository).
In my original version of the code, I provided a protected default constructor for my base class template:
template <typename VAL_TYPE> class LazyType_Base {
Then in one of the derived classes:
template <typename VAL_TYPE> class LazyType_Eager : public LazyType_Base<VAL_TYPE> { public: LazyType_Eager( VAL_TYPE&& final_val) : LazyType_Base<VAL_TYPE>{} , val_{final_val} {}
This compiles simply using Clang ++, but in g ++ 5.1 I get this error:
In file included from Test_OptionallyLazy.cpp:3:0: OptionallyLazy.hpp: In instantiation of 'LazyType_Eager<VAL_TYPE>::LazyType_Eager(VAL_TYPE&&) [with VAL_TYPE = int]': Test_OptionallyLazy.cpp:22:14: required from here OptionallyLazy.hpp:23:5: error: 'LazyType_Base<VAL_TYPE>::LazyType_Base() [with VAL_TYPE = int]' is protected LazyType_Base(void) =default; ^ OptionallyLazy.hpp:58:23: error: within this context , val_{final_val}
What's going on here? The strangest bit is that another derived class is doing something similar that does not cause an error.
Replacing the constructor =default with an explicit =default implementation {} fixes the compiler error.
EDIT: Thanks to TC, here is a real MCVE:
class Meow { protected: Meow(void) =default; public: virtual void f() {} }; class Purr : public Meow { public: Purr() : Meow{} {} };
c ++ protected templates c ++ 14
Kyle strand
source share