c++ - inherited protected defaulted constructor is not accessible -
3trying compile code below icc return error: error #453: protected function "a::a()" (declared @ line 10) not accessible through "a" pointer or object.
class { protected: constexpr a() = default; ~a() = default; a(const a&) = delete; }; class b : protected { public: b() = default; }; int main() { b b; } i found 3 weird ways make compilable:
- making ctor of public
- removing deleted copy ctor of a
- replacing "= default;" "{}" in ctor of a
i mean, why h.. ?
thank answers :)
i confirm misbehaviour on v13.1.3 (linux). compiler bug arne mertz says: find if a provided otherwise pointless data member initialized @ declaration, class compiles, e.g.
class { protected: constexpr a() = default; ~a() = default; a(const a&) = delete; private: char placate_intel_compiler_bug = 0; }; i don't know compiler version have, don't know if supports non-static data member initialization (or if same fix work you), if 5th workaround might consider merit intent unmistakable.
removing constexpr has no effect on bug.
of 3 workarounds found third one, replacing defaulted a::a() explicit a::a(){} 1 not mess desired public behaviour of class.
arne mertz's 3b works me 1 has downside of putting solution outside class a.
if in real world have particular reason declaring a::a() constexpr bear in mind, 3rd workaround, if constexpr constructor not default-ed c++11 standard § 7.1.5, para 4, places rather fiddly constraints on constructor , class make code more fragile in maintenance. possible plus in-your-face 5th workaround.
Comments
Post a Comment