Search code examples
c++inheritanceoperator-overloadingconstantsusing-declaration

using declarations and const overloads


Suppose I have two versions of operator-> (overloaded on const) in a base class. If I say

using Base::operator->;

in a derived class, will I get access to both versions or just the non-const one?


Solution

  • Same business as name hiding. It's all or nothing. Using declarations (7.3.3) bring a name, not a member.

    ISO/IEC 14882 (2003), 7.3.3. 1/ A using-declaration introduces a name into the declarative region in which the using-declaration appears. That name is a synonym for the name of some entity declared elsewhere.

    I encourage you to read 7.3.3, there are subtle things inside. You cannot using-declare a template, all the members refered by the name you using-declare must be accessible, the names are considerd for overload resolution alongside the names in the block the using declaration is found (ie. they don't hide anything), etc, etc.