Sign in to follow this  

using class::method

This topic is 3193 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've just forgotten the usage of something like class::method in a Class e,g. class X: private Y{ using Y::m;//?? just forgotten what this does any link ?? }

Share this post


Link to post
Share on other sites
Consider:

class Base
{
public:
void OverloadedFunction(int);
};

class Derived : public Base
{
public:
void OverloadedFunction(std::string);
};

Derived d;
d.OverloadedFunction(10);


The lookup process first looks for the function by name. It finds that OverloadedFunction exists inside class Derived, so it stops. Then, the lookup process identifies the function by type. So, it looks for an overload of Derived::OverloadedFunction that would take an integer argument, but finds none (because Derived::OverloadedFunction takes a string argument).

In order to have the lookup look for the correct overload both in the derived class and the base class, you have to import all the overloads from the base class into the derived class. Which is why you write:

class Derived : public Base
{
public:
using Base::OverloadedFunction;
void OverloadedFunction(std::string);
};


This (mostly) renames Base::OverloadedFunction(int) as Derived::OverloadedFunction(int), which lets the lookup succeed.

Share this post


Link to post
Share on other sites

This topic is 3193 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this