'using' keyword with multiple overloads

Viewed 63

I have been reading how to use using-declaration and was wondering what happened when I have multiple overloads. In the examples given, it looks as if this is all or nothing or is it possible to pull only a certain signature in scope?

Suppose I have the following classes:

class A
{
public:
   void function(int value);
   void function(double value);
   void function(const char *value);
};


class B : public A
{
public:
    using A::function;
    void function(uint64_t value);
};

Now in class B with the using keyword, I introduce the base class members into my class namespace. But this means that all of them are now available, right? Or can I also specify the signature, because I only want to introduce one of them, but not all. From the examples given, I would expect no. So in this case, I would have to move the declaration of such a function to protected or private to disable access to it, right?

1 Answers

It's all or nothing, you can't pick only specific overloads.

I would have to move the declaration of such a function to protected or private to disable access to it, right?

It wouldn't work. If you move even some of them to private, then using A::function; will apparently cause an error.

And if you make them protected, it wouldn't do anything, because using ... changes the access level on names you give it (i.e. if the using is public, the inherited functions become public too).

Related