Jump to content
  • Advertisement
Sign in to follow this  
nlbs

using class::method

This topic is 3475 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!