Reputation: 263118
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?
Upvotes: 4
Views: 298
Reputation: 56956
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.
Upvotes: 4
Reputation: 33655
both. did you try it? (damn this answer is short: ah well, here is example:
#include <iostream>
#include <string>
struct bar
{
void foo() { std::cout << "non_c:foo()" << std::endl; }
void foo() const { std::cout << "c:foo()" << std::endl; }
};
class base
{
public:
bar* operator->() { return &b; }
bar const* operator->() const { return &b; }
private:
bar b;
};
class derived : public base
{
public:
using base::operator->;
};
int main(void)
{
const derived d = derived();
derived e;
d->foo();
e->foo();
}
Upvotes: 2
Reputation: 96241
You get access to all versions of a method/operator with the same name in that parent.
Upvotes: 3